/// <summary>
        /// 添加或更新券后价展示配置
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public bool UpSertVendorProductCouponPriceConfig(VendorProductCouponPriceConfigModel model, string user)
        {
            var result = false;

            try
            {
                var oldValue = dbScopeManagerConfigurationRead.Execute(conn =>
                                                                       _dal.GetVendorProductCouponPriceConfig(conn, model.ProductType, model.Pid));
                if (oldValue == null)
                {
                    var pkid = dbScopeManagerConfiguration.Execute
                                   (conn => _dal.AddVendorProductCouponPriceConfig(conn, model));
                    result = pkid > 0;
                    if (result)
                    {
                        model.PKID               = pkid;
                        model.CreateDateTime     = DateTime.Now;
                        model.LastUpdateDateTime = DateTime.Now;
                        var log = new OprVendorProductModel()
                        {
                            LogType     = "VendorProductCouponPriceConfig",
                            IdentityId  = $"{model.ProductType}_{model.Pid}",
                            OldValue    = null,
                            NewValue    = JsonConvert.SerializeObject(model),
                            Remarks     = $"添加{model.ProductType}:{model.Pid}的券后价展示配置",
                            OperateUser = user,
                        };
                        LoggerManager.InsertLog("OprVendorProduct", log);
                    }
                }
                else
                {
                    model.CreateDateTime     = oldValue.CreateDateTime;
                    model.LastUpdateDateTime = DateTime.Now;
                    result = dbScopeManagerConfiguration.Execute(conn =>
                                                                 _dal.UpdateVendorProductCouponPriceConfig(conn, model));
                    if (result)
                    {
                        var log = new OprVendorProductModel()
                        {
                            LogType     = "VendorProductCouponPriceConfig",
                            IdentityId  = $"{model.ProductType}_{model.Pid}",
                            OldValue    = JsonConvert.SerializeObject(oldValue),
                            NewValue    = JsonConvert.SerializeObject(model),
                            Remarks     = $"更新{model.ProductType}:{model.Pid}的券后价展示配置",
                            OperateUser = user,
                        };
                        LoggerManager.InsertLog("OprVendorProduct", log);
                    }
                }
            }
            catch (Exception ex)
            {
                Logger.Error("UpSertVendorProductCouponPriceConfig", ex);
            }
            return(result);
        }
        /// <summary>
        /// 券后价展示配置是否重复
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public bool IsExistVendorProductCouponPriceConfig(VendorProductCouponPriceConfigModel model)
        {
            var result = true;

            try
            {
                result = dbScopeManagerConfigurationRead.Execute(conn =>
                                                                 _dal.IsExistVendorProductCouponPriceConfig(conn, model));
            }
            catch (Exception ex)
            {
                Logger.Error("IsExistVendorProductCouponPriceConfig", ex);
            }
            return(result);
        }
 /// <summary>
 /// 更新供应商产品券后价展示配置
 /// </summary>
 /// <param name="conn"></param>
 /// <param name="model"></param>
 /// <returns></returns>
 public bool UpdateVendorProductCouponPriceConfig(SqlConnection conn, VendorProductCouponPriceConfigModel model)
 {
     #region Sql
     var sql = @"UPDATE  Configuration.dbo.VendorProductCouponPriceConfig
                 SET     IsShow = @IsShow ,
                         LastUpdateDateTime = GETDATE()
                 WHERE   PKID = @PKID;";
     #endregion
     var parameters = new[]
     {
         new SqlParameter("@IsShow", model.IsShow),
         new SqlParameter("@PKID", model.PKID)
     };
     return(SqlHelper.ExecuteNonQuery(conn, CommandType.Text, sql, parameters) > 0);
 }
 /// <summary>
 /// 添加供应商产品券后价展示配置
 /// </summary>
 /// <param name="conn"></param>
 /// <param name="model"></param>
 /// <returns></returns>
 public int AddVendorProductCouponPriceConfig(SqlConnection conn, VendorProductCouponPriceConfigModel model)
 {
     #region SQL
     var sql = @"INSERT  INTO Configuration..VendorProductCouponPriceConfig
                         ( ProductType, Pid, IsShow )
                 OUTPUT  inserted.PKID
                 VALUES  ( @ProductType, @Pid, @IsShow );";
     #endregion
     var parameters = new[]
     {
         new SqlParameter("@Pid", model.Pid),
         new SqlParameter("@ProductType", model.ProductType),
         new SqlParameter("@IsShow", model.IsShow)
     };
     return(Convert.ToInt32(SqlHelper.ExecuteScalar(conn, CommandType.Text, sql, parameters)));
 }
Example #5
0
        public ActionResult UpsertConfig(VendorProductCouponPriceConfigModel model)
        {
            if (string.IsNullOrWhiteSpace(model.Pid))
            {
                return(Json(new { Status = false, Msg = "请选择服务Pid" }, JsonRequestBehavior.AllowGet));
            }
            var manager = new VendorProductCouponPriceManager();
            var isExist = manager.IsExistVendorProductCouponPriceConfig(model);

            if (isExist)
            {
                return(Json(new { Status = false, Msg = "已存在重复的数据,不能重复添加" }, JsonRequestBehavior.AllowGet));
            }
            var result = manager.UpSertVendorProductCouponPriceConfig(model, User.Identity.Name);

            return(Json(new { Status = result, Msg = $"操作{(result ? "成功" : "失败")}" }, JsonRequestBehavior.AllowGet));
        }
 /// <summary>
 /// 供应商产品券后价展示配置是否重复
 /// </summary>
 /// <param name="conn"></param>
 /// <param name="model"></param>
 /// <returns></returns>
 public bool IsExistVendorProductCouponPriceConfig(SqlConnection conn, VendorProductCouponPriceConfigModel model)
 {
     #region Sql
     var sql = @"SELECT  COUNT(1)
                 FROM    Configuration..VendorProductCouponPriceConfig AS s WITH ( NOLOCK )
                 WHERE   s.Pid = @Pid
                         AND s.ProductType = @ProductType
                         AND s.IsDeleted = 0
                         AND s.PKID <> @PKID;";
     #endregion
     var parameters = new[]
     {
         new SqlParameter("@Pid", model.Pid),
         new SqlParameter("@ProductType", model.ProductType),
         new SqlParameter("@PKID", model.PKID)
     };
     return(Convert.ToInt32(SqlHelper.ExecuteScalar(conn, CommandType.Text, sql, parameters)) > 0);
 }