public async Task <bool> UpdateBorrow(Guid id, UpdateBorrowDto model, string fields) { var borrow = await _service.Query(id, false); borrow.UpdateTime = DateTime.Now; return(await _service.Update(CommonClass.SetModelValue(model, borrow, fields))); }
public async Task <IActionResult> UpdateBorrow(Guid id, [FromBody] UpdateBorrowDto model, [FromQuery] string fields) { try { if (!await _manager.UpdateBorrow(id, model, fields)) { return(Ok(new JsonMessageResult("修改失败!", 0, 0))); } return(NoContent()); } catch (Exception e) { _logger.LogError(e, e.Message); return(Ok(new JsonMessageResult(e.Message, 0, 0))); } }
public async Task <ActionResult <Borrow> > PutBorrow(int id, UpdateBorrowDto update) { var type = (TypeEnum)TypeEnum.Parse(typeof(TypeEnum), User.Claims.FirstOrDefault(c => c.Type == "Type").Value); if (type != TypeEnum.Admin) { return(Unauthorized()); } var borrow = await _context.Borrow.Include(b => b.Book).FirstOrDefaultAsync(b => b.BorrowId == id); var rule = await _context.Rule.FirstOrDefaultAsync(r => r.Type == type); var duedate = borrow.BorrowDate.AddDays(rule.LimitDay); var book = await _context.Book.FirstOrDefaultAsync(b => b.BookID == borrow.Book.BookID); if (update.Status == TypeEnum.Losted && duedate < DateTime.Now) { borrow.Fines = book.Price * 2 + (5 * (int)((DateTime.Now - duedate).TotalDays)); } else if (update.Status == TypeEnum.Losted) { borrow.Fines = book.Price * 2; } else if (update.Status == TypeEnum.Late) { borrow.Fines = 5 * (int)((DateTime.Now - duedate).TotalDays); } borrow.Status = update.Status; await _context.SaveChangesAsync(); return(NoContent()); }