public async Task AddScore(ScoreInputDto input) { var userId = ((UserIdentity)User.Identity).UserId; if (!await db.Suppliers.AnyAsync(m => m.Id == input.SupplierId && !m.IsDelete)) { throw new HttpResponseException(new HttpResponseMessage() { Content = new StringContent(JsonConvert.SerializeObject(new ResponseApi() { Code = EExceptionType.Implement, Message = "该供应商不存在" })) }); } db.Scores.Add(new Score() { Id = IdentityManager.NewId(), Fraction = input.Fraction, SupplierId = input.SupplierId, AddbyId = userId }); if (await db.SaveChangesAsync() <= 0) { throw new HttpResponseException(new HttpResponseMessage() { Content = new StringContent(JsonConvert.SerializeObject(new ResponseApi() { Code = EExceptionType.Implement, Message = "添加失败" })) }); } }
public async Task UpdateScore(ScoreInputDto input) { var userId = ((UserIdentity)User.Identity).UserId; var data = await db.Scores.SingleOrDefaultAsync(m => m.Id == input.ScoreId && !m.IsDelete); if (data == null) { throw new HttpResponseException(new HttpResponseMessage() { Content = new StringContent(JsonConvert.SerializeObject(new ResponseApi() { Code = EExceptionType.Implement, Message = "评分信息不存在" })) }); } if (!await db.Suppliers.AnyAsync(m => m.Id == input.SupplierId && !m.IsDelete)) { throw new HttpResponseException(new HttpResponseMessage() { Content = new StringContent(JsonConvert.SerializeObject(new ResponseApi() { Code = EExceptionType.Implement, Message = "供应商不存在" })) }); } data.Fraction = input.Fraction; data.SupplierId = input.SupplierId; if (await db.SaveChangesAsync() <= 0) { throw new HttpResponseException(new HttpResponseMessage() { Content = new StringContent(JsonConvert.SerializeObject(new ResponseApi() { Code = EExceptionType.Implement, Message = "更新失败" })) }); } }