Ejemplo n.º 1
0
        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);
        }
Ejemplo n.º 2
0
        public static void AddGarbageFromStock(Stock stock, int quantity)
        {
            Garbage garbage = GetAllGarbages().FirstOrDefault(x => x.Item_Id.Equals(stock.Item_Id) && x.Stock_Id.Equals(stock.Id));

            if (garbage != null)
            {
                garbage.Quantity   += quantity;
                garbage.EntityState = EntityState.Modified;
            }
            else
            {
                garbage = new Garbage()
                {
                    Item_Id     = (int)stock.Item_Id,
                    Stock_Id    = stock.Id,
                    Quantity    = quantity,
                    CreatedAt   = DateTime.Now,
                    EntityState = EntityState.Added
                };
            }

            stock.Quantity -= quantity;
            StockController.ManageStock(stock, EntityState.Modified);
            ManageGarbage(garbage, garbage.EntityState);
        }
Ejemplo n.º 3
0
        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);
        }