团餐订单
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

DtoValidator.cs 2.8 KiB

11 months ago
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. 
  2. using BPA.KitChen.GroupMealOrder.Core.Entity;
  3. using BPA.KitChen.GroupMealOrder.Core.Enum;
  4. using BPA.KitChen.GroupMealOrder.SqlSugar;
  5. using MySqlConnector;
  6. using System.Collections.Generic;
  7. using System.ComponentModel.DataAnnotations;
  8. namespace BPA.KitChen.GroupMealOrder.Application.BaseDto
  9. {
  10. /// <summary>
  11. /// Dto参数验证
  12. /// </summary>
  13. public class DtoValidator
  14. {
  15. /// <summary>
  16. /// 验证会员
  17. /// </summary>
  18. /// <param name="id"></param>
  19. /// <returns></returns>
  20. public static ValidationResult Member(string id)
  21. {
  22. var data = SqlSugarDb.Db.Queryable<BPA_MemberInfo>().First(x => x.Id == id&&x.IsDeleted==0);
  23. return data == null ? new ValidationResult("会员不存在") : ValidationResult.Success;
  24. }
  25. /// <summary>
  26. /// 验证会员标签的合法性
  27. /// </summary>
  28. /// <param name="id"></param>
  29. /// <returns></returns>
  30. public static ValidationResult MemberTag(string id)
  31. {
  32. var data = SqlSugarDb.Db.Queryable<BPA_MemberTag>().First(x=>x.Id==id);
  33. return data == null ? new ValidationResult("会员标签不存在") : ValidationResult.Success;
  34. }
  35. /// <summary>
  36. /// 验证会员标签的合法性
  37. /// </summary>
  38. /// <param name="id"></param>
  39. /// <returns></returns>
  40. public static ValidationResult MemberTagList(List<string> ids)
  41. {
  42. var data = SqlSugarDb.Db.Queryable<BPA_MemberTag>().Where(x => ids.Contains(x.Id) && x.IsDeleted == 0&&x.Status== CommonStatus.ENABLE).ToList();
  43. return data.Count<=0 ? new ValidationResult("会员标签不存在") : ValidationResult.Success;
  44. }
  45. /// <summary>
  46. /// 会员平台
  47. /// </summary>
  48. /// <param name="type"></param>
  49. /// <returns></returns>
  50. public static ValidationResult MemberPlatformType(int type)
  51. {
  52. return !System.Enum.IsDefined(typeof(PlatformType), type) ? new ValidationResult("平台类型不存在") : ValidationResult.Success;
  53. }
  54. /// <summary>
  55. /// 会员平台
  56. /// </summary>
  57. /// <param name="type"></param>
  58. /// <returns></returns>
  59. public static ValidationResult Status(int type)
  60. {
  61. return !System.Enum.IsDefined(typeof(CommonStatus), type) ? new ValidationResult("状态错误") : ValidationResult.Success;
  62. }
  63. /// <summary>
  64. /// 优惠券使用
  65. /// </summary>
  66. /// <param name="type"></param>
  67. /// <returns></returns>
  68. public static ValidationResult CouponUseType(int type)
  69. {
  70. return !System.Enum.IsDefined(typeof(CouponUseType), type) ? new ValidationResult("状态错误") : ValidationResult.Success;
  71. }
  72. }
  73. }