public static void RefundItem(Item item, Stock stock, User user, int quantity) { // item operations if (stock != null) { stock.UpdatedAt = DateTime.Now; } stock.EntityState = EntityState.Modified; // borrowing operations Borrow borrow = BorrowController.DoesAlreadyEnrolledBySameUser(user.Id, stock.Id); if (borrow != null) { borrow = item.Borrows.First(x => x.Id.Equals(borrow.Id)); borrow.Quantity -= quantity; stock.Quantity += quantity; if (borrow.Quantity == 0) { borrow.IsReturn = true; borrow.ReturnTime = DateTime.Now; } borrow.EntityState = EntityState.Modified; } StockController.ManageStock(stock, EntityState.Modified); ManageItem(item, item.EntityState); }
public static void AddGarbageFromBorrow(Borrow borrow, int quantity) { Garbage garbage = GetAllGarbages().FirstOrDefault(x => x.Item_Id.Equals(borrow.Item_Id) && x.Stock_Id.Equals(borrow.Stock_Id)); if (garbage != null) { garbage.Quantity += quantity; garbage.EntityState = EntityState.Modified; } else { garbage = new Garbage() { Item_Id = borrow.Item_Id, Stock_Id = borrow.Stock_Id, Quantity = quantity, CreatedAt = DateTime.Now, EntityState = EntityState.Added }; } borrow.Quantity -= quantity; BorrowController.ManageBorrow(borrow, EntityState.Modified); ManageGarbage(garbage, garbage.EntityState); }
public static void BorrowItem(Item item, Stock stock, User user, int quantity) { // item operations if (stock != null) { stock.UpdatedAt = DateTime.Now; } stock.EntityState = EntityState.Modified; // borrowing operations Borrow borrow = BorrowController.DoesAlreadyEnrolledBySameUser(user.Id, stock.Id); if (borrow != null) { borrow = item.Borrows.First(x => x.Id.Equals(borrow.Id)); stock.Quantity += borrow.Quantity; borrow.Quantity += quantity; stock.Quantity -= borrow.Quantity; borrow.BorrowTime = DateTime.Now; borrow.ReturnTime = null; borrow.IsReturn = false; borrow.EntityState = EntityState.Modified; } else { borrow = new Borrow() { User = user, User_Id = user.Id, BorrowTime = DateTime.Now, IsReturn = false, Item_Id = item.Id, Stock_Id = stock.Id, Quantity = quantity, EntityState = EntityState.Added }; stock.Quantity -= borrow.Quantity; BorrowController.ManageBorrow(borrow, borrow.EntityState); } StockController.ManageStock(stock, EntityState.Modified); ManageItem(item, item.EntityState); }