/// <summary>
        /// Creates a Consumption Event
        /// </summary>
        /// <param name="consumptionEvent"></param>
        /// <param name="user"></param>
        public void CreateConsumptionEvent(ConsumptionEvent consumptionEvent, ClaimsPrincipal user)
        {
            consumptionEvent.AddedBy     = user.Identity.Name;
            consumptionEvent.UpdatedBy   = user.Identity.Name;
            consumptionEvent.DateAdded   = DateTime.Now;
            consumptionEvent.DateUpdated = DateTime.Now;

            Context.ConsumptionEvents.Add(consumptionEvent);
            Context.SaveChanges();
        }
Beispiel #2
0
        public IActionResult Create()
        {
            var consumptionEvent = new ConsumptionEvent()
            {
                DateConsumed = DateTime.Now,
                ConsumedBy   = User.Identity.Name
            };

            return(View(consumptionEvent));
        }
Beispiel #3
0
        public IActionResult CreateFromItem(string sourceId)
        {
            var consumptionEvent = new ConsumptionEvent()
            {
                DateConsumed    = DateTime.Now,
                ConsumedBy      = User.Identity.Name,
                InventoryItemId = sourceId
            };

            return(View(consumptionEvent));
        }
Beispiel #4
0
        public IActionResult Create(ConsumptionEvent consumptionEvent)
        {
            if (ModelState.IsValid)
            {
                _eventService.CreateConsumptionEvent(consumptionEvent, User);
                TempData["SuccessMessage"] = "Consumption Event Created";

                return(RedirectToAction("Edit", new { id = consumptionEvent.ConsumptionEventId }));
            }

            return(View());
        }
Beispiel #5
0
        public IActionResult CreateFromItem(string sourceId, ConsumptionEvent consumptionEvent)
        {
            if (ModelState.IsValid)
            {
                consumptionEvent.InventoryItemId = sourceId;
                _eventService.CreateConsumptionEvent(consumptionEvent, User);
                TempData["SuccessMessage"] = "Consumption Event Created";

                return(RedirectToAction("Edit", "Items", new { id = consumptionEvent.InventoryItemId }));
            }

            return(View("CreateFromItem", consumptionEvent));
        }
        /// <summary>
        /// Edit the Consumption Event
        /// </summary>
        /// <param name="id"></param>
        public void UpdateConsumptionEvent(ConsumptionEvent consumptionEvent, ClaimsPrincipal user)
        {
            var eventToUpdate = Context.ConsumptionEvents.AsNoTracking().Where(x => x.ConsumptionEventId == consumptionEvent.ConsumptionEventId).FirstOrDefault();

            consumptionEvent.UpdatedBy   = user.Identity.Name;
            consumptionEvent.DateUpdated = DateTime.Now;

            if (eventToUpdate != null)
            {
                Context.ConsumptionEvents.Update(consumptionEvent);
                Context.SaveChanges();
            }
        }
Beispiel #7
0
        public void stock_quantity_evaluates(decimal? qtyPurchased, int consumptionCount, int consumptionValue, 
            int? expectedStockQty, string expectedStockLevel)
        {
            //+ Arrange
            var item = new InventoryItem();
            item.ConsumptionEventsNavigation = new List<ConsumptionEvent>();

            //if (qtyPurchased != null)
            //{
                item.QtyPurchased = qtyPurchased;
            //}

            for (var i = 0; i < consumptionCount; i++)
            {
                var consumptionEvent = new ConsumptionEvent() { QuantityConsumed = consumptionValue };
                item.ConsumptionEventsNavigation.Add(consumptionEvent);
            }

            //+ Assert
            Assert.Equal(expectedStockQty, item.StockQuantity);
            Assert.Equal(expectedStockLevel, item.StockLevel);
        }