using BPA.KitChen.GroupMealOrder.Core.Entity; using BPA.KitChen.GroupMealOrder.Core.Enum; using BPA.KitChen.GroupMealOrder.SqlSugar; using MySqlConnector; using System.Collections.Generic; using System.ComponentModel.DataAnnotations; namespace BPA.KitChen.GroupMealOrder.Application.BaseDto { /// /// Dto参数验证 /// public class DtoValidator { /// /// 验证会员 /// /// /// public static ValidationResult Member(string id) { var data = SqlSugarDb.Db.Queryable().First(x => x.Id == id&&x.IsDeleted==0); return data == null ? new ValidationResult("会员不存在") : ValidationResult.Success; } /// /// 验证会员标签的合法性 /// /// /// public static ValidationResult MemberTag(string id) { var data = SqlSugarDb.Db.Queryable().First(x=>x.Id==id); return data == null ? new ValidationResult("会员标签不存在") : ValidationResult.Success; } /// /// 验证会员标签的合法性 /// /// /// public static ValidationResult MemberTagList(List ids) { var data = SqlSugarDb.Db.Queryable().Where(x => ids.Contains(x.Id) && x.IsDeleted == 0&&x.Status== CommonStatus.ENABLE).ToList(); return data.Count<=0 ? new ValidationResult("会员标签不存在") : ValidationResult.Success; } /// /// 会员平台 /// /// /// public static ValidationResult MemberPlatformType(int type) { return !System.Enum.IsDefined(typeof(PlatformType), type) ? new ValidationResult("平台类型不存在") : ValidationResult.Success; } /// /// 会员平台 /// /// /// public static ValidationResult Status(int type) { return !System.Enum.IsDefined(typeof(CommonStatus), type) ? new ValidationResult("状态错误") : ValidationResult.Success; } /// /// 优惠券使用 /// /// /// public static ValidationResult CouponUseType(int type) { return !System.Enum.IsDefined(typeof(CouponUseType), type) ? new ValidationResult("状态错误") : ValidationResult.Success; } } }