Beispiel #1
0
        public async Task <Message> PutEmp(string id, [FromBody] Dictionary <string, object> dictionary)
        {
            if (!dictionary.ContainsKey("employeeName") || !dictionary.ContainsKey("password"))
            {
                return(Message.Fail().Add("content", "参数错误"));
            }
            string employeename = (string)dictionary["employeeName"];
            string password     = (string)dictionary["password"];

            var dbitem = await _employeeRepository.GetSingleAsync(x => x.JobId == id);

            if (dbitem == null)
            {
                return(Message.NotFound());
            }
            EmployeeModification employeeModification = new EmployeeModification();

            if (!string.IsNullOrEmpty(password) && password.Length < 8)
            {
                return(Message.Fail().Add("content", "密码长度小于8"));
            }
            employeeModification.JobId    = id;
            employeeModification.Password = password;
            employeeModification.Name     = employeename;
            _mapper.Map(employeeModification, dbitem);
            _employeeRepository.Update(dbitem);
            if (!await _unitOfWork.SaveAsync())
            {
                return(Message.ServerError());
            }
            return(Message.Ok());
        }
Beispiel #2
0
        public async Task <Message> PutEmp(string id, [FromBody] EmployeeModification employeeModification)
        {
            if (employeeModification == null)
            {
                return(Message.Fail());
            }


            var dbitem = await _employeeRepository.GetSingleAsync(x => x.JobId == id);

            if (dbitem == null)
            {
                return(Message.NotFound());
            }
            employeeModification.JobId = dbitem.JobId;
            _mapper.Map(employeeModification, dbitem);
            _employeeRepository.Update(dbitem);
            if (!await _unitOfWork.SaveAsync())
            {
                return(Message.ServerError());
            }
            return(Message.Ok());
        }