コード例 #1
0
        public OperateResult <Auth_User> Update(UserParam param)
        {
            var repo = _unitOfWork.GetRepository <Auth_User>();
            var old  = repo.Find(param.Id);

            if (old == null)
            {
                return(OperateResult <Auth_User> .Error("对象不存在", old));
            }
            //判断职位是否存在
            if (!_db.Auth_Job.Any(l => l.Id == param.JobId))
            {
                return(OperateResult <Auth_User> .Error("所选职位不存在"));
            }
            if (_db.Auth_User.Any(l => l.UserName == param.UserName && l.Id != param.Id))
            {
                return(OperateResult <Auth_User> .Error("账号重复", old));
            }
            old.UserName   = param.UserName;
            old.JobId      = param.JobId;
            old.Code       = param.Code;
            old.RealName   = param.RealName;
            old.Password   = param.Password.To32MD5();
            old.Sex        = param.Sex;
            old.IdCard     = param.IdCard;
            old.Email      = param.Email;
            old.Telephone  = param.Telephone;
            old.Phone      = param.Phone;
            old.Address    = param.Address;
            old.Remark     = param.Remark;
            old.ModifyTime = DateTime.Now;
            old.Type       = param.Type;
            repo.Update(old);
            var sucess = _unitOfWork.SaveChanges() == 1;//提交到数据库

            return(new OperateResult <Auth_User>(sucess ? ResultCode.OK : ResultCode.Error, sucess ? "成功" : "失败", old));
        }
コード例 #2
0
        public OperateResult <Auth_User> Add(UserParam param)
        {
            if (_db.Auth_User.Any(l => l.UserName == param.UserName))
            {
                return(OperateResult <Auth_User> .Error("账号重复"));
            }
            //判断职位是否存在
            if (!_db.Auth_Job.Any(l => l.Id == param.JobId))
            {
                return(OperateResult <Auth_User> .Error("所选职位不存在"));
            }
            var obj = param.ToEntity();

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

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

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