Exemple #1
0
        public OperateResult <Auth_Role> Update(AuthRoleParam param)
        {
            var repo = _unitOfWork.GetRepository <Auth_Role>();
            var old  = GetById(param.Id);

            if (old == null)
            {
                return(OperateResult <Auth_Role> .Error("对象不存在", old));
            }
            if (_db.Auth_Role.Any(l => l.Name == param.Name && l.Id != param.Id))
            {
                return(OperateResult <Auth_Role> .Error("名称重复", old));
            }
            //if (_db.Auth_Role.Any(l => l.Code == param.Code && l.Id != param.Id))
            //{
            //    return OperateResult<Auth_Role>.Error("编码重复", old);
            //}
            old.Sort = param.Sort;
            old.Name = param.Name;
            //old.Code = param.Code;//这个编码不允许修改
            old.Remark     = param.Remark;
            old.ModifyTime = DateTime.Now;
            repo.Update(old);
            var sucess = _unitOfWork.SaveChanges() == 1;//提交到数据库

            return(new OperateResult <Auth_Role>(sucess ? ResultCode.OK : ResultCode.Error, sucess ? "成功" : "失败", old));
        }
        public ActionResult <OperateResult <Auth_Role> > Put([FromBody] AuthRoleParam value)
        {
            var result = Json(_service.Update(value));

            _cacheHelp.UpdateRoleCache();
            return(result);
        }
Exemple #3
0
        public OperateResult <Auth_Role> Add(AuthRoleParam param)
        {
            if (_db.Auth_Role.Any(l => l.Name == param.Name))
            {
                return(OperateResult <Auth_Role> .Error("名称重复"));
            }
            //if (_db.Auth_Role.Any(l => l.Code == param.Code))
            //{
            //    return OperateResult<Auth_Role>.Error("编码重复");
            //}
            var obj = param.ToEntity();

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

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

            return(new OperateResult <Auth_Role>(sucess ? ResultCode.OK : ResultCode.Error, sucess ? "成功" : "失败", obj));
        }