/// <summary>
        /// 更新蓄电池极速达配置
        /// </summary>
        /// <param name="model"></param>
        /// <param name="productModels"></param>
        /// <returns></returns>
        public Tuple <bool, bool> UpdateBatteryFastDelivery(BatteryFastDeliveryModel model, List <BatteryFastDeliveryProductsModel> productModels)
        {
            var result      = false;
            var cacheResult = true;

            try
            {
                var existProducts = dbScopeManagerConfigRead.Execute(conn => DalBatteryFastDelivery.GetBatteryFastDeliveryProductsByFastDeliveryId(conn, model.PKID.ToString()));
                if ((productModels == null || !productModels.Any()) && (existProducts == null || !existProducts.Any()))
                {
                    result = dbScopeManagerConfig.Execute(conn => DalBatteryFastDelivery.UpdateBatteryFastDelivery(conn, model));
                }
                else
                {
                    dbScopeManagerConfig.CreateTransaction(conn =>
                    {
                        var updateMain     = DalBatteryFastDelivery.UpdateBatteryFastDelivery(conn, model);
                        productModels      = productModels ?? new List <BatteryFastDeliveryProductsModel>();
                        existProducts      = existProducts ?? new List <BatteryFastDeliveryProductsModel>();
                        var updateProducts = UpdateBatteryFastDeliveryProducts(conn, model.RegionId, productModels, existProducts);
                        if (updateMain && updateProducts)
                        {
                            var refreshPids = productModels.Select(s => s.ProductPid).Union(existProducts.Select(e => e.ProductPid)).ToList();
                            cacheResult     = RefreshFastDeliveryServiceCache(model.RegionId, refreshPids);
                            result          = true;
                        }
                    });
                }
            }
            catch (Exception ex)
            {
                Logger.Error("UpdateBatteryFastDelivery", ex);
            }
            return(Tuple.Create(result, cacheResult));
        }
        public Tuple <bool, bool> AddBatteryFastDelivery(BatteryFastDeliveryModel model, List <BatteryFastDeliveryProductsModel> productModels)
        {
            var result      = false;
            var cacheResult = true;

            try
            {
                dbScopeManagerConfig.CreateTransaction(conn =>
                {
                    var fastDeliveryId = DalBatteryFastDelivery.AddBatteryFastDelivery(conn, model);
                    if (fastDeliveryId > 0)
                    {
                        if (productModels != null && productModels.Any())
                        {
                            foreach (var productModel in productModels)
                            {
                                productModel.FastDeliveryId = fastDeliveryId;
                                var insertResult            = DalBatteryFastDelivery.AddBatteryFastDeliveryProducts(conn, productModel);
                            }
                            cacheResult = RefreshFastDeliveryServiceCache(model.RegionId, productModels.Select(s => s.ProductPid).ToList());
                        }
                        result = true;
                    }
                });
            }
            catch (Exception ex)
            {
                Logger.Error("AddBatteryFastDelivery", ex);
            }
            return(Tuple.Create(result, cacheResult));
        }
示例#3
0
        public ActionResult AddBatteryFastDelivery(BatteryFastDeliveryModel model, List <BatteryFastDeliveryProductsModel> productModels)
        {
            if (model.RegionId < 1)
            {
                return(Json(new { Status = false, Msg = "请选择区域信息" }, JsonRequestBehavior.AllowGet));
            }
            if (string.IsNullOrWhiteSpace(model.ServiceTypePid))
            {
                return(Json(new { Status = false, Msg = "请选择蓄电池极速达服务类目" }, JsonRequestBehavior.AllowGet));
            }
            var manager  = new BatteryFastDeliveryConfigManager();
            var isRepeat = manager.IsRepeatBatteryFastDelivery(model.ServiceTypePid, model.RegionId);

            if (isRepeat)
            {
                return(Json(new { Status = false, Msg = $"已存在重复数据" }, JsonRequestBehavior.AllowGet));
            }
            var result = manager.AddBatteryFastDelivery(model, productModels);

            if (!result.Item1)
            {
                return(Json(new { Status = false, Msg = "添加失败" }, JsonRequestBehavior.AllowGet));
            }
            else
            {
                return(Json(new { Status = true, Msg = "添加成功,刷新缓存" + (result.Item2 ? "成功" : "失败") }, JsonRequestBehavior.AllowGet));
            }
        }
        public static int AddBatteryFastDelivery(SqlConnection conn, BatteryFastDeliveryModel model)
        {
            var sql        = @"INSERT  Configuration..BatteryFastDelivery
                     ( ServiceTypePid ,
                       RegionId ,
                       StartTime ,
                       EndTime ,
                       Remark
                     )
                    VALUES  ( @ServiceTypePid ,
                              @RegionId ,
                              @StartTime ,
                              @EndTime ,
                              @Remark
                    )
                    SELECT  SCOPE_IDENTITY();";
            var parameters = new[]
            {
                new SqlParameter("@ServiceTypePid", model.ServiceTypePid),
                new SqlParameter("@RegionId", model.RegionId),
                new SqlParameter("@StartTime", model.StartTime == null ? DBNull.Value : (object)model.StartTime.Value),
                new SqlParameter("@EndTime", model.EndTime == null ? DBNull.Value : (object)model.EndTime.Value),
                new SqlParameter("@Remark", model.Remark)
            };
            var pkid = Convert.ToInt32(SqlHelper.ExecuteScalar(conn, CommandType.Text, sql, parameters));

            return(pkid);
        }
        public bool ChangeBatteryFastDeliveryStatus(int pkid, bool isEnabled, string user)
        {
            var success = false;

            try
            {
                List <string>            products = null;
                BatteryFastDeliveryModel config   = null;
                dbScopeManagerConfigRead.Execute(conn =>
                {
                    config = DalBatteryFastDelivery.SelectBatteryFastDeliveryById(conn, pkid);
                    if (config != null)
                    {
                        var list = DalBatteryFastDelivery.GetBatteryFastDeliveryProductsByFastDeliveryId(conn, pkid.ToString());
                        products = list.Select(x => x.ProductPid).ToList();
                    }
                    products = products ?? new List <string>();
                });
                if (config != null && config.IsEnabled != isEnabled)
                {
                    success = dbScopeManagerConfig.Execute(conn => DalBatteryFastDelivery.UpdateBatteryFastDeliveryStatus(conn, pkid, isEnabled));
                }
                if (success)
                {
                    RecordOperationLog(new BaoYangOprLog
                    {
                        LogType     = "BatteryFastDelivery",
                        Remarks     = $"{(isEnabled ? "启用配置" : "禁用配置")}",
                        OldValue    = JsonConvert.SerializeObject(new { PKID = pkid, IsEnabled = !isEnabled }),
                        NewValue    = JsonConvert.SerializeObject(new { PKID = pkid, IsEnabled = isEnabled }),
                        IdentityID  = pkid.ToString(),
                        OperateUser = user,
                    });
                    RefreshFastDeliveryServiceCache(config.RegionId, products);
                }
            }
            catch (Exception ex)
            {
                Logger.Error("ChangeBatteryFastDeliveryStatus", ex);
            }
            return(success);
        }
        public static bool UpdateBatteryFastDelivery(SqlConnection conn, BatteryFastDeliveryModel batteryFastDeliveryModel)
        {
            var sql        = @"UPDATE  Configuration..BatteryFastDelivery
                        SET     StartTime = @StartTime,
                                EndTime=@EndTime,
                                Remark=@Remark,
                                LastUpdateDateTime=@LastUpdateDateTime
                        WHERE   PKID = @PKID;";
            var parameters = new[]
            {
                new SqlParameter("@StartTime", batteryFastDeliveryModel.StartTime),
                new SqlParameter("@EndTime", batteryFastDeliveryModel.EndTime),
                new SqlParameter("@Remark", batteryFastDeliveryModel.Remark),
                new SqlParameter("@PKID", batteryFastDeliveryModel.PKID),
                new SqlParameter("@LastUpdateDateTime", DateTime.Now)
            };
            var count = SqlHelper.ExecuteNonQuery(conn, CommandType.Text, sql, parameters);

            return(count > 0);
        }
示例#7
0
        public ActionResult UpdateBatteryFastDelivery(BatteryFastDeliveryModel model, List <BatteryFastDeliveryProductsModel> productModels)
        {
            if (model.PKID < 1)
            {
                return(Json(new { Status = false, Msg = "未知的更新对象" }, JsonRequestBehavior.AllowGet));
            }
            if (model.RegionId < 1 || string.IsNullOrWhiteSpace(model.ServiceTypePid))
            {
                return(Json(new { Status = false, Msg = "区域信息及服务类目不能为空" }, JsonRequestBehavior.AllowGet));
            }
            var manager = new BatteryFastDeliveryConfigManager();
            var result  = manager.UpdateBatteryFastDelivery(model, productModels);

            if (!result.Item1)
            {
                return(Json(new { Status = false, Msg = "更新失败" }, JsonRequestBehavior.AllowGet));
            }
            else
            {
                return(Json(new { Status = true, Msg = "更新成功,刷新缓存" + (result.Item2 ? "成功" : "失败") }, JsonRequestBehavior.AllowGet));
            }
        }