public OperateResult <Auth_Menu> Update(AuthMenuParam param)
        {
            var repo = _unitOfWork.GetRepository <Auth_Menu>();
            var old  = repo.Find(param.Id);

            if (old == null)
            {
                return(OperateResult <Auth_Menu> .Error("对象不存在", old));
            }
            //校验父级菜单是否存在
            if (!_db.Auth_Menu.Any(l => l.Id == param.ParentId))
            {
                return(OperateResult <Auth_Menu> .Error("父级菜单不存在"));
            }
            old.Sort       = param.Sort;
            old.Name       = param.Name;
            old.Code       = param.Code;
            old.Remark     = param.Remark;
            old.ParentId   = param.ParentId;
            old.Url        = param.Url;
            old.MenuIcon   = param.MenuIcon;
            old.ModifyTime = DateTime.Now;
            repo.Update(old);
            var sucess = _unitOfWork.SaveChanges() == 1;//提交到数据库

            return(new OperateResult <Auth_Menu>(sucess ? ResultCode.OK : ResultCode.Error, sucess ? "成功" : "失败", old));
        }
        public OperateResult <Auth_Menu> Add(AuthMenuParam param)
        {
            //校验父级菜单是否存在
            if (!_db.Auth_Menu.Any(l => l.Id == param.ParentId))
            {
                return(OperateResult <Auth_Menu> .Error("父级菜单不存在"));
            }
            var obj = param.ToEntity();

            if (obj.Id == Guid.Empty)
            {
                obj.Id = Guid.NewGuid();
            }
            var repo = _unitOfWork.GetRepository <Auth_Menu>();

            repo.Insert(obj);
            var sucess = _unitOfWork.SaveChanges() == 1;

            return(new OperateResult <Auth_Menu>(sucess ? ResultCode.OK : ResultCode.Error, sucess ? "成功" : "失败", obj));
        }
예제 #3
0
 public ActionResult <OperateResult <Auth_Menu> > Put([FromBody] AuthMenuParam value)
 {
     return(Json(_service.Update(value)));
 }