Exemplo n.º 1
0
        public bool UpdateVipBaoYangPackage(VipBaoYangPackageViewModel package)
        {
            var success = false;

            try
            {
                var inputPackage = new VipBaoYangPackageDbModel(package);
                VipBaoYangPackageDbModel dbPackage = null;
                var oldData = string.Empty;
                dbScopeManager.CreateTransaction(conn =>
                {
                    dbPackage            = DALVipBaoYangPackage.SelectVipBaoYangPackageByPkid(conn, package.PKID);
                    dbPackage.OilConfigs = DALVipBaoYangPackage.SelectBaoYangPackageOilConfigs(conn, package.PKID).ToList();
                    oldData = JsonConvert.SerializeObject(dbPackage);
                    dbPackage.OilConfigs = inputPackage.OilConfigs;
                    if (dbPackage != null)
                    {
                        var updateResult = DALVipBaoYangPackage.UpdateVipBaoYangPackage(conn, package);
                        if (updateResult > 0)
                        {
                            success = DALVipBaoYangPackage.DeleteBaoYangPackageOilConfigs(conn, package.PKID);
                            if (success)
                            {
                                dbPackage.OilConfigs.ForEach(x => DALVipBaoYangPackage.InsertBaoYangPackageOilConfig(conn, x));
                            }
                        }
                    }
                });

                if (success)
                {
                    dbPackage.LastUpdateDateTime = DateTime.Now;
                    var newData = JsonConvert.SerializeObject(dbPackage);
                    InsertLog(dbPackage.PID, oldData, newData, "Update", package.CreateUser);
                }
            }
            catch (Exception ex)
            {
                logger.Error(ex);
            }

            return(success);
        }
Exemplo n.º 2
0
        /// <summary>
        /// 添加保养套餐
        /// </summary>
        /// <param name="package"></param>
        /// <returns></returns>
        public bool InsertVipBaoYangPackage(VipBaoYangPackageViewModel package)
        {
            var result    = false;
            var productId = string.Empty;

            try
            {
                dbScopeManager.CreateTransaction(conn =>
                {
                    var insertPackage = new VipBaoYangPackageDbModel(package);
                    var pkid          = DALVipBaoYangPackage.InsertVipBaoYangPackage(conn, insertPackage);
                    if (pkid > 0)
                    {
                        insertPackage.OilConfigs.ForEach(x => x.PackageId = pkid);
                        insertPackage.OilConfigs.ForEach(config => DALVipBaoYangPackage.InsertBaoYangPackageOilConfig(conn, config));
                        productId = $"BY-TUHU-BXGSDCBY|{pkid.ToString()}";
                        result    = DALVipBaoYangPackage.UpdateVipBaoYangPackagePID(conn, pkid, productId) > 0;
                    }
                    if (result)
                    {
                        package.PKID = pkid;
                        package.PID  = productId;
                        VipBaoYangPackageService.CreateProduct(pkid.ToString(), package.PackageName, package.CreateUser);
                    }
                });

                if (result)
                {
                    InsertLog(productId, null, JsonConvert.SerializeObject(package), "Insert", package.CreateUser);
                }
            }
            catch (Exception ex)
            {
                logger.Error(ex);
            }

            return(result);
        }
Exemplo n.º 3
0
        public bool SyncOilConfigData()
        {
            bool success = false;

            try
            {
                var oldOilConfigs = dbScopeReadManager.Execute(conn => DALVipBaoYangPackage.SelectBaoYangPackageOilOldConfig(conn));
                var oilConfigs    = oldOilConfigs.SelectMany(x =>
                {
                    var list      = new List <VipBaoYangPackageOilConfig>();
                    var packageId = x.Key;
                    var brands    = x.Value;
                    if (!string.IsNullOrWhiteSpace(brands))
                    {
                        if (brands.Contains("["))
                        {
                            var brandConfigs = JsonConvert.DeserializeAnonymousType(x.Value,
                                                                                    new[] { new { Brand = "", Grades = new List <int>() } }.ToList()).Select(b => new
                            {
                                b.Brand,
                                Grades = b.Grades.Select(grade => grade == 1 ? "矿物油" : (grade == 2 ? "半合成" : (grade == 3 ? "全合成" : string.Empty))),
                            });
                            var configs = brandConfigs.SelectMany(b => b.Grades.Select(grade => new VipBaoYangPackageOilConfig
                            {
                                Brand     = b.Brand,
                                Grade     = grade,
                                PackageId = packageId,
                                Series    = string.Empty,
                            }));
                            list.AddRange(configs);
                        }
                        else
                        {
                            var brandList = brands.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
                            var configs   = brandList.Select(b => new VipBaoYangPackageOilConfig
                            {
                                Brand     = b,
                                Grade     = string.Empty,
                                Series    = string.Empty,
                                PackageId = packageId,
                            });
                            list.AddRange(configs);
                        }
                    }
                    return(list);
                });
                var groups = oilConfigs.GroupBy(x => x.PackageId).ToList();
                dbScopeManager.CreateTransaction(conn =>
                {
                    foreach (var group in groups)
                    {
                        if (!DALVipBaoYangPackage.IsExistsBaoYangPackageOilConfigForSync(conn, group.Key))
                        {
                            foreach (var item in group)
                            {
                                item.PKID = DALVipBaoYangPackage.InsertBaoYangPackageOilConfig(conn, item);
                            }
                        }
                    }
                    success = true;
                });
            }
            catch (Exception ex)
            {
                logger.Error(ex.Message, ex);
            }
            return(success);
        }