Exemple #1
0
 public static bool Update(SE_MDBeautyBrandConfigModel model)
 {
     try
     {
         return(SE_MDBeautyBrandConfigDAL.Update(ProcessConnection.OpenTuhu_Groupon, model));
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
        public ActionResult BatchEdit(int parentId = 0)
        {
            SE_MDBeautyBrandConfigModel model = new SE_MDBeautyBrandConfigModel()
            {
                Id         = 0,
                ParentId   = parentId,
                CreateTime = DateTime.Now,
                IsDisable  = false
            };

            return(View(model));
        }
        public ActionResult BatchSave(SE_MDBeautyBrandConfigModel model)
        {
            bool result = false;

            if (model != null)
            {
                if (model.ParentId > 0)
                {
                    result = SE_MDBeautyBrandConfigBLL.BatchInsert(model);
                }
            }
            return(RedirectToAction("Index"));
        }
        public ActionResult Edit(int id = 0, int parentId = 0)
        {
            SE_MDBeautyBrandConfigModel model = new SE_MDBeautyBrandConfigModel()
            {
                ParentId = parentId
            };

            if (id > 0)
            {
                model = SE_MDBeautyBrandConfigBLL.Select(id) ?? new SE_MDBeautyBrandConfigModel();
            }

            ViewBag.ZTreeJsonEdit = SE_MDBeautyCategoryConfigController.SE_MDBeautyCategoryTreeJson(model.CategoryIds, true);

            return(View(model));
        }
        public static bool BatchInsert(SqlConnection connection, SE_MDBeautyBrandConfigModel model)
        {
            int    executeNum     = 0;
            var    _brandNameList = model?.BrandName.Split(',');
            string sql            = @"
                INSERT INTO [SE_MDBeautyBrandConfig]
                           ([ParentId]
                           ,[CategoryIds]
                           ,[BrandName]
                           ,[IsDisable]
                           ,[CreateTime])
                     VALUES
                           (@ParentId
                           ,@CategoryIds
                           ,@BrandName
                           ,@IsDisable
                           ,@CreateTime)";

            using (IDbConnection conn = connection)
            {
                IDbTransaction transaction = conn.BeginTransaction();
                try
                {
                    for (int i = 0; i < _brandNameList.Length; i++)
                    {
                        model.BrandName = _brandNameList[i] ?? "";
                        if (!string.IsNullOrWhiteSpace(model.BrandName))
                        {
                            executeNum += conn.Execute(sql, model, transaction);
                        }
                    }
                    transaction.Commit();
                }
                catch (Exception ex)
                {
                    transaction.Rollback();
                }
                finally
                {
                    if (executeNum != _brandNameList.Length)
                    {
                        transaction.Rollback();
                    }
                }
            }
            return(executeNum == _brandNameList.Length);
        }
        public ActionResult Save(SE_MDBeautyBrandConfigModel model)
        {
            bool result = false;

            if (model != null)
            {
                if (model.Id > 0)
                {
                    result = SE_MDBeautyBrandConfigBLL.Update(model);
                }
                else
                {
                    result = SE_MDBeautyBrandConfigBLL.Insert(model);
                }
            }
            return(RedirectToAction("Index"));
        }
        public static bool Update(SqlConnection connection, SE_MDBeautyBrandConfigModel model)
        {
            //修改状态时,若有子级则修改子级状态
            using (IDbConnection conn = connection)
            {
                //string sql = @" UPDATE [SE_MDBeautyBrandConfig]
                //                   SET [ParentId] = @ParentId
                //                      ,[CategoryIds] = @CategoryIds
                //                      ,[BrandName] = @BrandName
                //                      ,[IsDisable] = @IsDisable
                //                      ,[CreateTime] = @CreateTime
                //                WHERE Id = @Id ";
                //return conn.Execute(sql, model) > 0;
                string sql = @" 
                                BEGIN
	                                DECLARE @childCount INT
	                                with cte_child as
	                                (
		                                select *,0 as lvl from SE_MDBeautyBrandConfig WITH(NOLOCK)
		                                where Id = @Id
		                                union all
		                                select b.*,lvl + 1 from cte_child AS c 
		                                INNER join SE_MDBeautyBrandConfig AS b WITH(NOLOCK)
		                                on c.Id = b.ParentId
	                                )
	                                SELECT * INTO #ChildTable from cte_child;
	                                SELECT @childCount = COUNT(1) from #ChildTable
	                                UPDATE [SE_MDBeautyBrandConfig]
                                                                   SET [ParentId] = @ParentId
                                                                      ,[CategoryIds] = @CategoryIds
                                                                      ,[BrandName] = @BrandName
                                                                      ,[IsDisable] = @IsDisable
                                                                      ,[CreateTime] = @CreateTime
                                                                WHERE Id = @Id
                                    IF(@childCount > 1)
		                                BEGIN
			                                UPDATE [SE_MDBeautyBrandConfig] 
			                                SET [IsDisable] = @IsDisable
			                                WHERE Id IN(select id from #ChildTable)
		                                END
	                                DROP TABLE #ChildTable
                                END ";
                return(conn.Execute(sql, model) > 0);
            }
        }
 public static bool Insert(SqlConnection connection, SE_MDBeautyBrandConfigModel model)
 {
     using (IDbConnection conn = connection)
     {
         string sql = @"
         INSERT INTO [SE_MDBeautyBrandConfig]
                    ([ParentId]
                    ,[CategoryIds]
                    ,[BrandName]
                    ,[IsDisable]
                    ,[CreateTime])
              VALUES
                    (@ParentId
                    ,@CategoryIds
                    ,@BrandName
                    ,@IsDisable
                    ,@CreateTime)";
         return(conn.Execute(sql, model) > 0);
     }
 }