Example #1
0
        public JsonResult InsertVipBaoYangPackage(VipBaoYangPackageViewModel model)
        {
            if (model == null)
            {
                return(Json(new { status = false, msg = "参数不能为空" }));
            }
            var validationResults = model.GetValidationResults();

            if (!string.IsNullOrEmpty(validationResults))
            {
                return(Json(new { status = false, msg = validationResults }));
            }

            if (manager.IsExistsPackageName(model.PackageName, model.PKID))
            {
                return(Json(new { status = false, msg = "套餐名称已存在" }));
            }
            model.CreateUser  = User.Identity.Name;
            model.GetRuleGUID = model.Source == "Interface" ? model.GetRuleGUID : Guid.Empty;
            var result = false;

            if (model.PKID <= 0)
            {
                result = manager.InsertVipBaoYangPackage(model);
            }
            else
            {
                result = manager.UpdateVipBaoYangPackage(model);
            }
            return(Json(new { status = result }));
        }
        public JsonResult InsertVipBaoYangPackage(VipBaoYangPackageViewModel model)
        {
            Func <string> validFunc = () =>
            {
                if (model == null)
                {
                    return("参数不能为空!");
                }
                if (string.IsNullOrWhiteSpace(model.PackageName))
                {
                    return("套餐名称不能为空");
                }
                SettlementMethod method;
                if (!Enum.TryParse(model.SettlementMethod, out method))
                {
                    return("结算方式不存在");
                }
                var gradesTmpl = new List <int> {
                    1, 2, 3
                };
                model.Brands = model.Brands?.Select(brand => new BaoYangPackageOilBrand
                {
                    Brand  = brand.Brand,
                    Grades = brand.Grades?.Where(x => gradesTmpl.Contains(x)).ToList() ?? new List <int>(),
                }).Where(brand => brand.Grades.Any()).ToList();
                if (model.Brands == null || !model.Brands.Any())
                {
                    return("品牌不能为空");
                }
                var brands = model.Brands.Select(x => x.Brand).ToList();
                if (brands.Distinct().Count() < brands.Count)
                {
                    return("机油品牌重复");
                }
                model.SettlementMethod = method.ToString();
                model.PackageName      = model.PackageName.Trim();
                if (manager.IsExistsPackageName(model.PackageName, model.PKID))
                {
                    return("套餐名称已存在");
                }
                return(string.Empty);
            };

            var validResult = validFunc();

            if (!string.IsNullOrEmpty(validResult))
            {
                return(Json(new { status = false, msg = validResult }));
            }
            model.CreateUser = User.Identity.Name;
            var result = false;

            if (model.PKID <= 0)
            {
                result = manager.InsertVipBaoYangPackage(model);
            }
            else if (User.Identity.Name == "*****@*****.**" ||
                     User.Identity.Name == "*****@*****.**" ||
                     User.Identity.Name == "*****@*****.**" ||
                     User.Identity.Name == "*****@*****.**" ||
                     User.Identity.Name == "*****@*****.**")
            {
                result = manager.UpdateVipBaoYangPackage(model);
            }
            return(Json(new { status = result }));
        }