public async Task AddProjeState(ProjectStateInputDto input) { if (await db.ProjectStates.AnyAsync(m => m.Name == input.ProjectStateName && !m.IsDelete)) { throw new HttpResponseException(new HttpResponseMessage() { Content = new StringContent(JsonConvert.SerializeObject(new ResponseApi() { Code = EExceptionType.Implement, Message = input.ProjectStateName + "该状态名称已存在" })) }); } var data = new ProjectState() { Id = IdentityManager.NewId(), Name = input.ProjectStateName, IsDelete = false }; db.ProjectStates.Add(data); if (await db.SaveChangesAsync() <= 0) { throw new HttpResponseException(new HttpResponseMessage() { Content = new StringContent(JsonConvert.SerializeObject(new ResponseApi() { Code = EExceptionType.Implement, Message = "添加失败" })) }); } }
public async Task UpdateProjeState(ProjectStateInputDto input) { if (await db.ProjectStates.AnyAsync(m => m.Name == input.ProjectStateName && !m.IsDelete)) { throw new HttpResponseException(new HttpResponseMessage() { Content = new StringContent(JsonConvert.SerializeObject(new ResponseApi() { Code = EExceptionType.Implement, Message = input.ProjectStateName + "该状态名称已存在" })) }); } var data = await db.ProjectStates.SingleOrDefaultAsync(m => m.Id == input.ProjectStateId); if (data == null) { throw new HttpResponseException(new HttpResponseMessage() { Content = new StringContent(JsonConvert.SerializeObject(new ResponseApi() { Code = EExceptionType.Implement, Message = input.ProjectStateName + input.ProjectStateId + "该项目状态不存在" })) }); } data.Name = input.ProjectStateName; if (await db.SaveChangesAsync() <= 0) { throw new HttpResponseException(new HttpResponseMessage() { Content = new StringContent(JsonConvert.SerializeObject(new ResponseApi() { Code = EExceptionType.Implement, Message = "添加失败" })) }); } }