public async Task Add(AtlasInputDto input) { if (await db.Atlas.AnyAsync(m => m.Name == input.Name)) { throw new HttpResponseException(new HttpResponseMessage() { Content = new StringContent(JsonConvert.SerializeObject(new ResponseApi() { Code = EExceptionType.Implement, Message = "已有该名称的图谱,请勿重复添加" })) }); } if (string.IsNullOrWhiteSpace(input.Url)) { throw new HttpResponseException(new HttpResponseMessage() { Content = new StringContent(JsonConvert.SerializeObject(new ResponseApi() { Code = EExceptionType.Implement, Message = "Url不允许为空" })) }); } db.Atlas.Add(new Models.Db.Aggregate.AtlasManagements.Atlas { Id = IdentityManager.NewId(), Name = input.Name, BatchNumber = input.BatchNumber, Desc = input.Desc, Url = input.Url, TestingTime = input.TestingTime }); if (await db.SaveChangesAsync() <= 0) { throw new HttpResponseException(new HttpResponseMessage() { Content = new StringContent(JsonConvert.SerializeObject(new ResponseApi() { Code = EExceptionType.Implement, Message = "添加失败" })) }); } }
public async Task Update(AtlasInputDto input) { if (await db.Atlas.AnyAsync(m => m.Name == input.Name && m.Id != input.AtlasId)) { throw new HttpResponseException(new HttpResponseMessage() { Content = new StringContent(JsonConvert.SerializeObject(new ResponseApi() { Code = EExceptionType.Implement, Message = "该图谱名称已存在" })) }); } var data = await db.Atlas.SingleOrDefaultAsync(m => m.Id == input.AtlasId); if (data == null) { throw new HttpResponseException(new HttpResponseMessage() { Content = new StringContent(JsonConvert.SerializeObject(new ResponseApi() { Code = EExceptionType.Implement, Message = "该谱图不存在" })) }); } data.Name = input.Name; data.BatchNumber = input.BatchNumber; data.Desc = input.Desc; data.TestingTime = input.TestingTime; data.Url = input.Url; if (await db.SaveChangesAsync() <= 0) { throw new HttpResponseException(new HttpResponseMessage() { Content = new StringContent(JsonConvert.SerializeObject(new ResponseApi() { Code = EExceptionType.Implement, Message = "修改失败" })) }); } }