public async Task <RESTResult> AddOrUpdateDepartmentAsync(DepartmentDataTransferObject departmentInfo, Guid userId, bool IsDeleted) { RESTResult result = new RESTResult { Code = RESTStatus.Failed }; if (Guid.Empty.Equals(departmentInfo.Id) || departmentInfo.Id == null) { //TODO:Add a new department var deparmentEntity = Mapper.Map <DepartmentDataTransferObject, Department>(departmentInfo); deparmentEntity.CreateTime = DateTime.Now; deparmentEntity.CreateByUserId = userId; await _departmentReposiotry.InsertAsync(deparmentEntity); result.Code = RESTStatus.Success; result.Message = "Add the department successful"; } else { //TODO:Update department var departmentEntity = await _departmentReposiotry.GetAsync(departmentInfo.Id.Value); if (departmentEntity.IsDeleted) { result.Message = "The department have been removed"; return(result); } if (departmentEntity != null) { departmentEntity.Name = string.IsNullOrEmpty(departmentInfo.Name) ? departmentEntity.Name : departmentInfo.Name; departmentEntity.ModifyByUserId = userId; departmentEntity.ModifyTime = DateTime.Now; departmentEntity.IsDeleted = IsDeleted; await _departmentReposiotry.UpdateAsync(departmentEntity); result.Code = RESTStatus.Success; result.Message = "update the department successful"; } } return(result); }
public async Task <IActionResult> AddOrUpdateDepartment([FromBody] DepartmentDataTransferObject departmentInfo) { return(Ok(await _userAppService.AddOrUpdateDepartmentAsync(departmentInfo, CurrentUser.Id.Value, false))); }