示例#1
0
        public JsonResult Edit(SysGroup model)
        {
            try
            {
                if (model.SysGroupId > 0)
                {
                    var entity = _sysGroupService.GetById(model.SysGroupId);
                    //修改
                    entity.UTime  = DateTime.Now;
                    entity.Name   = model.Name;
                    entity.SortNo = model.SortNo;
                    _sysGroupService.Update(entity);
                }
                else
                {
                    if (_sysGroupService.IsExistName(model.Name))
                    {
                        return(Json(new { Status = Successed.Repeat }, JsonRequestBehavior.AllowGet));
                    }
                    //添加
                    model.IsEnable = (int)EnumHelp.EnabledEnum.效;
                    model.CTime    = DateTime.Now;
                    model.UTime    = DateTime.Now;

                    _sysGroupService.Insert(model);
                }
                return(Json(new { Status = Successed.Ok }, JsonRequestBehavior.AllowGet));
            }
            catch (Exception)
            {
                return(Json(new { Status = Successed.Error }, JsonRequestBehavior.AllowGet));
            }
        }
示例#2
0
        public IActionResult Update(SysGroupModel model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }
            var existedMessage = CheckExistCode(model.Code, model.Id);

            if (existedMessage.Length > 0)
            {
                return(BadRequest(new ResultHandle {
                    Status = false, Message = existedMessage
                }));
            }
            model.UserModified     = currentUser.UserID;
            model.DatetimeModified = DateTime.Now;
            var hs      = sysGroupService.Update(model, x => x.Id == model.Id);
            var message = HandleError.GetMessage(hs, Crud.Update);

            ResultHandle result = new ResultHandle {
                Status = hs.Success, Message = stringLocalizer[message].Value
            };

            if (!hs.Success)
            {
                return(BadRequest(result));
            }
            return(Ok(result));
        }