public void EditOne(Permission_AddEditDTO editOne, string updater)
        {
            using (MiniSenDbContext dbContext = new MiniSenDbContext())
            {
                CommonService <Permission> commonService = new CommonService <Permission>(dbContext);

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

                bool hasExist = commonService.WhereNoMarkDeleted().Where(p => 0 == p.DelFlag && p.Id != editOne.Id && p.ApiUrl.Equals(editOne.ApiUrl)).Any();
                if (hasExist)
                {
                    throw new PushToUserException($"A api permission item with the same api url '{editOne.ApiUrl}' already exists");
                }

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

                dbContext.Update <Permission>(p => new { p.Name, p.ApiType, p.ApiUrl, p.ApiMethod, p.RemarkInfo, p.SortNumber, p.Updater, p.UpdateTime }, updateOne)
                .Where(d => d.Id.Equals(updateOne.Id)).Done();
            }
        }
Beispiel #2
0
        public ActionResult editItem(Permission_AddEditDTO editOne)
        {
            if (!ModelState.IsValid)
            {
                throw new PushToUserException(MVCHelper.GetValidMsgStr(ModelState));
            }

            editOne.ApiUrl = Utils.UrlToHump(editOne.ApiUrl.Trim('/'));
            PermissionService.EditOne(editOne, LoginUserId);

            return(Json(new AjaxResult {
                Status = "success", SendData = new { Result = "success" }
            }));
        }
        public string AddNewOne(Permission_AddEditDTO addOne, string creater)
        {
            using (MiniSenDbContext dbContext = new MiniSenDbContext())
            {
                CommonService <Permission> commonService = new CommonService <Permission>(dbContext);

                bool hasExist = commonService.WhereNoMarkDeleted().Where(p => 0 == p.DelFlag && p.ApiUrl.Equals(addOne.ApiUrl)).Any();
                if (hasExist)
                {
                    throw new PushToUserException($"A api permission item with the same api url '{addOne.ApiUrl}' already exists");
                }

                Permission newOne = CoffeeMapper <Permission_AddEditDTO, Permission> .AutoMap(addOne, (_out, _in) =>
                {
                    _out.Id             = Utils.GetGuidStr();
                    _out.Creater        = creater;
                    _out.PermissionType = 1;
                });

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