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

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

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

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

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

            DictionaryService.EditOne(editOne, LoginUserId);

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

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

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

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