Example #1
0
        public void EditOne(Role_AddEditDTO editOne, string updater)
        {
            using (MiniSenDbContext dbContext = new MiniSenDbContext())
            {
                CommonService <Role> commonService = new CommonService <Role>(dbContext);

                bool isExist = commonService.AnyByIdNoMarkDeleted(editOne.Id);
                if (!isExist)
                {
                    throw new PushToUserException("Current dictionary item is not exist");
                }

                bool hasExist = commonService.WhereNoMarkDeleted().Where(d => 0 == d.DelFlag && d.Id != editOne.Id && d.Name.Equals(editOne.Name)).Any();
                if (hasExist)
                {
                    throw new PushToUserException($"A dictionary item with the same name '{editOne.Name}' already exists");
                }

                Role updateOne = CoffeeMapper <Role_AddEditDTO, Role> .AutoMap(editOne, (_out, _in) =>
                {
                    _out.Updater    = updater;
                    _out.UpdateTime = DateTime.Now;
                });

                dbContext.Update <Role>(d => new { d.Name, d.SortNumber, d.RemarkInfo, d.Updater, d.UpdateTime }, updateOne)
                .Where(d => d.Id.Equals(updateOne.Id)).Done();
            }
        }
        public ActionResult editItem(Role_AddEditDTO editOne)
        {
            if (!ModelState.IsValid)
            {
                throw new PushToUserException(MVCHelper.GetValidMsgStr(ModelState));
            }

            RoleService.EditOne(editOne, LoginUserId);

            return(Json(new AjaxResult {
                Status = "success", SendData = new { Result = "success" }
            }));
        }
Example #3
0
        public string AddNewOne(Role_AddEditDTO addOne, string creater)
        {
            using (MiniSenDbContext dbContext = new MiniSenDbContext())
            {
                CommonService <Role> commonService = new CommonService <Role>(dbContext);

                bool hasExist = commonService.WhereNoMarkDeleted().Where(d => 0 == d.DelFlag && d.Name.Equals(addOne.Name)).Any();
                if (hasExist)
                {
                    throw new PushToUserException($"A dictionary item with the same name '{addOne.Name}' already exists");
                }

                Role newOne = CoffeeMapper <Role_AddEditDTO, Role> .AutoMap(addOne, (_out, _in) =>
                {
                    _out.Id      = Utils.GetGuidStr();
                    _out.Creater = creater;
                });

                return(commonService.Insert(newOne));
            }
        }