public ActionResult DeleteItem(int id, string prodName) { try { InventoryLineItem iLI = _inventoryLineItemBL.GetInventoryLineItemById ((int)HttpContext.Session.GetInt32("LocId"), (int)_orderLineItemBL.GetCustomerOrderLineItemById(id, _productBL.GetProductByName(prodName).Id).ProdId); iLI.Quantity += _orderLineItemBL.GetCustomerOrderLineItemById(id, _productBL.GetProductByName(prodName).Id).Quantity; _inventoryLineItemBL.UpdateInventoryLineItem(iLI); _orderLineItemBL.DeleteCustomerOrderLineItem(_orderLineItemBL.GetCustomerOrderLineItemById(id, _productBL.GetProductByName(prodName).Id)); //Log.Information($"Customer deleted-- Email: {email}"); return(RedirectToAction("Cart")); } catch (Exception e) { /*Helper.WriteError(e, "Error"); * Helper.WriteFatal(e, "Fatal"); * Helper.WriteVerbose(e, "Verbose");*/ CustomerCart cart = new CustomerCart(); cart.CustId = _customerBL.GetCustomerByEmail(HttpContext.Session.GetString("UserEmail")).Id; cart.LocId = _locationBL.GetLocationById((int)HttpContext.Session.GetInt32("LocId")).Id; cart.CurrentItemsId = _orderLineItemBL.Ident_Curr() + 1; _cartBL.UpdateCustomerCart(cart); CustomerOrderLineItem orderLineItem = new CustomerOrderLineItem(); orderLineItem.OrderId = cart.CurrentItemsId; orderLineItem.ProdId = null; orderLineItem.Quantity = 0; orderLineItem.ProdPrice = 0; _orderLineItemBL.AddCustomerOrderLineItem(orderLineItem); return(Redirect($"/InventoryLineItem?locId={HttpContext.Session.GetInt32("LocId")}")); } //return View(); }
public void UpdateInventory(CustomerOrderLineItem orderItem) { InventoryLineItem invItem = _inventoryLineItemsBL.GetInventoryLineItemById((int)_location.Id, (int)orderItem.ProdId); invItem.Quantity -= orderItem.Quantity; _inventoryLineItemsBL.UpdateInventoryLineItem(_inventoryLineItemsBL.GetInventoryLineItemById((int)_location.Id, (int)orderItem.ProdId), invItem); }
public void UpdateInventoryLineItem(InventoryLineItem inventoryLineItem2BUpdated, InventoryLineItem updatedDetails) { inventoryLineItem2BUpdated.InventoryId = updatedDetails.InventoryId; inventoryLineItem2BUpdated.ProductId = updatedDetails.ProductId; inventoryLineItem2BUpdated.Quantity = updatedDetails.Quantity; _repo.UpdateInventoryLineItem(inventoryLineItem2BUpdated); }
public async Task <IActionResult> DecrementStockItem(InventoryLineItem ili) { if (CurrentManager == null) { return(await LoginRedirectActionTask); } if (CurrentStock == null) { return(await Task.Factory.StartNew(() => RedirectToAction("ManageLocationStock", "Manager"))); } InventoryLineItem processedILI = await GetProductForILIAsync(ili); List <InventoryLineItem> tempStock = CurrentStock; try { var incrementedLineItem = tempStock.Where(sli => sli.ProductId == processedILI.ProductId).First(); incrementedLineItem.ProductQuantity -= 1; string updateILIRequest = $"location/stock/update"; await this.PutDataAsync(updateILIRequest, incrementedLineItem); } catch (HttpRequestException e) { //TODO: Do something if the request to the API fails. var message = e.Message; Console.WriteLine(message); } return(RedirectToAction("ManageLocationStock", new { locationId = ManagedLocation.Id })); }
public async Task <IActionResult> AddItemToCart(InventoryLineItem ili) { if (CurrentCustomer == null) { return(await LoginRedirectActionTask); } if (CurrentCart == null) { CurrentCart = new List <InventoryLineItem>(); } InventoryLineItem processedILI = await GetProductForILIAsync(ili); List <InventoryLineItem> tempCart = CurrentCart; try { tempCart.Where(sli => sli.ProductId == processedILI.ProductId).First().ProductQuantity += 1; } catch (InvalidOperationException e) { var message = e.Message; StagedLineItem newSLI = new StagedLineItem(processedILI.Product, 1, processedILI); InventoryLineItem newILI = new InventoryLineItem(CurrentLocation, processedILI.Product, 1); tempCart.Add(newILI); } CurrentCart = tempCart; return(RedirectToAction("ViewInventoryAtLocation", new { locationId = CurrentLocation.Id })); }
private void LoadDataFromCSV() { Debug.Log("Loading Data from CSV"); inventoryLineItems = new List <InventoryLineItem>(); StreamReader sReader = null; FileInfo statusFile = new FileInfo("Inventory.csv"); if (statusFile != null && statusFile.Exists) { sReader = (StreamReader)statusFile.OpenText(); sReader.ReadLine(); // Skip header row while (!sReader.EndOfStream) { string line = sReader.ReadLine(); var values = removeQuotedStrings(line).Split(','); for (int i = 0; i < values.Length; i++) { values[i] = values[i].Replace("&Comma&", ","); } InventoryLineItem newLineItem = new InventoryLineItem(); newLineItem.ProductCode = values[0]; newLineItem.ProductDescription = values[1]; int.TryParse(values[2], out newLineItem.ProductCategoryCode); newLineItem.TharisaPLC1 = values[3]; newLineItem.MainCatagory2 = values[4]; newLineItem.SubArea3 = values[5]; newLineItem.ProductCategoryDescription = values[6]; newLineItem.PlantArea4 = values[7]; newLineItem.STATGROUP5 = values[8]; newLineItem.STATGROUP6 = values[9]; newLineItem.STATGROUP7 = values[10]; newLineItem.STATGROUP8 = values[11]; newLineItem.ItemStatus = values[12]; newLineItem.StatisticalGroupCode = values[13]; newLineItem.StatisticalGroupCodeDescription = values[14]; newLineItem.BinLocation = values[15]; newLineItem.BinLocationType = values[16]; int.TryParse(values[17], out newLineItem.QuantityOnOrder); int.TryParse(values[18], out newLineItem.StockOnHand); int.TryParse(values[19], out newLineItem.MaxStockQTY); int.TryParse(values[20], out newLineItem.ReorderQTY); float.TryParse(values[21], out newLineItem.SafetyStockQTY); string movingAVGpriceString = values[22].Replace("-", "0"); movingAVGpriceString = movingAVGpriceString.Replace(",", ""); movingAVGpriceString = movingAVGpriceString.Replace("$", ""); float.TryParse(values[22], out newLineItem.MovingAveragePrice); string totalValueString = values[23].Replace("-", "0"); totalValueString = totalValueString.Replace(",", ""); float.TryParse(totalValueString, System.Globalization.NumberStyles.Any, new System.Globalization.CultureInfo("en-US"), out newLineItem.TotalValueofItem); //Debug.Log("string: " + totalValueString + " added: " + newLineItem.TotalValueofItem); inventoryLineItems.Add(newLineItem); } sReader.Close(); } }
public async Task <IActionResult> RemoveItemFromCart(InventoryLineItem ili) { if (CurrentCustomer == null) { return(await LoginRedirectActionTask); } if (CurrentCart == null) { CurrentCart = new List <InventoryLineItem>(); } InventoryLineItem processedILI = await GetProductForILIAsync(ili); List <InventoryLineItem> tempCart = CurrentCart; try { tempCart.Where(sli => sli.ProductId == processedILI.ProductId).First().ProductQuantity -= 1; tempCart.RemoveAll(sli => sli.ProductQuantity < 1); } catch (InvalidOperationException e) {// TODO: What happens if removing an item doesn't work here? } CurrentCart = tempCart; return(RedirectToAction("ViewInventoryAtLocation", new { locationId = CurrentLocation.Id })); }
private void AddLineItemToCart(InventoryLineItem selection, int quantityOrdered) { Log.Logger.Information("Adding a staged line item to the user's order cart.."); StagedLineItem newLineItem = new StagedLineItem(selection.Product, quantityOrdered, selection); OrderCart.Add(newLineItem); }
public void UpdateInventoryLineItemShouldUpdateLineItem() { //Arrange var options = new DbContextOptionsBuilder <IceShopContext>().UseInMemoryDatabase("UpdateInventoryLineItemShouldUpdateLineItem").Options; using var testContext = new IceShopContext(options); // add sample data to testContext testContext.InventoryLineItems.AddRange(SampleData.GetSampleInventoryLineItems()); // This data needs to be added so that navigation properties of the Inventory Line Items aren't null. testContext.Locations.AddRange(SampleData.GetSampleLocations()); testContext.Products.AddRange(SampleData.GetSampleProducts()); testContext.SaveChanges(); repo = new DBRepo(testContext); //Act // get a location that has an InventoryLineItem int sampleLocationId = repo.GetAllLocations().First().Id; InventoryLineItem sampleLineItem = repo.GetAllInventoryLineItemsAtLocation(sampleLocationId).FindLast(ili => ili.LocationId == sampleLocationId); int startingQuantity = sampleLineItem.ProductQuantity; sampleLineItem.ProductQuantity += 1; repo.UpdateInventoryLineItem(sampleLineItem); repo.SaveChanges(); //Assert //using var assertContext = new IceShopContext(options); Assert.NotEqual(startingQuantity, sampleLineItem.ProductQuantity); }
private async Task <InventoryLineItem> GetProductForILIAsync(InventoryLineItem ili) {// TODO: This function is a duplicate from the CustomerController. Needs its own class. string productsRequest = $"product/get"; var receivedProducts = await this.GetDataAsync <List <Product> >(productsRequest); ili.Product = receivedProducts.First(p => p.Id == ili.ProductId); return(ili); }
public InvLineItemCRVM cast2InventoryLineItemCRVM(InventoryLineItem inventoryLineItem) { return(new InvLineItemCRVM { ProductId = inventoryLineItem.ProductId, Quantity = inventoryLineItem.Quantity, }); }
public void UpdateInventoryLineItem(InventoryLineItem inventoryLineItem2BUpated) { Entity.InventoryLineItem oldInventoryLineItem = _context.InventoryLineItems.Find(inventoryLineItem2BUpated.Id); _context.Entry(oldInventoryLineItem).CurrentValues.SetValues(_mapper.ParseInventoryLineItem(inventoryLineItem2BUpated)); _context.SaveChanges(); _context.ChangeTracker.Clear(); }
private async Task <InventoryLineItem> GetProductForILIAsync(InventoryLineItem ili) { string productsRequest = $"product/get"; var receivedProducts = await this.GetDataAsync <List <Product> >(productsRequest); ili.Product = receivedProducts.First(p => p.Id == ili.ProductId); return(ili); }
public InventoryLineItem GetItemDetails(Product item) { InventoryLineItem newLineItem = new InventoryLineItem(); newLineItem.InventoryId = _location.Id; newLineItem.ProductId = item.Id; newLineItem.Quantity = 20; return(newLineItem); }
public void UpdateInventoryLineItemInRepo(InventoryLineItem lineItem) { if (lineItem.ProductQuantity < 1) { RemoveInventoryLineItemInRepo(lineItem); return; } Log.Logger.Information("Updating an existing inventory line item in the repository.."); repo.UpdateInventoryLineItem(lineItem); repo.SaveChanges(); }
public StagedLineItem GetStagedLineItemForAffectedLineItemIfItExists(InventoryLineItem inventoryLineItem) { Log.Logger.Information("Checking to see if an inventory line item has been added to the order cart already.."); if (OrderCart.Exists(sli => sli.affectedInventoryLineItem == inventoryLineItem)) { return(OrderCart.FindLast(sli => sli.affectedInventoryLineItem == inventoryLineItem)); } else { return(null); } }
public InvLineItemEditVM cast2InventoryLineItemEditVM(InventoryLineItem inventoryLineItem, Product product) { return(new InvLineItemEditVM { InventoryId = inventoryLineItem.InventoryId, ProductId = inventoryLineItem.ProductId, ProdName = product.ProdName, ProdPrice = product.ProdPrice, Quantity = inventoryLineItem.Quantity, Id = inventoryLineItem.Id }); }
public InventoryLineItem UpdateInventoryLineItem(InventoryLineItem inventoryLineItem2BUpdated) { InventoryLineItem oldInventoryLineItem = _context.InventoryLineItems.Find(inventoryLineItem2BUpdated.Id); _context.Entry(oldInventoryLineItem).CurrentValues.SetValues(inventoryLineItem2BUpdated); _context.SaveChanges(); //This method clears the change tracker to drop all tracked entities _context.ChangeTracker.Clear(); return(inventoryLineItem2BUpdated); }
public OrderItemVM cast2OrderItemVM(InventoryLineItem inventoryLineItem2BCasted, Product product) { return(new OrderItemVM { InventoryId = inventoryLineItem2BCasted.InventoryId, ProductId = inventoryLineItem2BCasted.ProductId, ProdName = product.ProdName, ProdPrice = product.ProdPrice, ProdBrandName = product.ProdBrandName, Quantity = inventoryLineItem2BCasted.Quantity, Id = inventoryLineItem2BCasted.Id }); }
public void StageProductForOrder(InventoryLineItem selection, int quantityOrdered) { StagedLineItem existingStagedLineItem = GetStagedLineItemForAffectedLineItemIfItExists(selection); if (existingStagedLineItem != null) { Log.Logger.Information("Changing the quantity of an existing line item in the order cart.."); existingStagedLineItem.Quantity += quantityOrdered; } else { AddLineItemToCart(selection, quantityOrdered); } }
public async Task <IActionResult> RemoveLineItemInStock(InventoryLineItem lineItemDTO) { try { var lineItem = _mapper.Map <InventoryLineItem>(lineItemDTO); _locationService.RemoveInventoryLineItemInRepo(lineItem); return(AcceptedAtAction("RemoveLineItemInStock", lineItemDTO)); } catch (Exception) { // TODO: Check if this is the right error code for this. return(StatusCode(500)); } }
public int GetAvailableQuantityOfInventoryLineItem(InventoryLineItem selectedLineItem) { Log.Logger.Information("Computing amount of product stock at a location that isn't already ordered by the current customer.."); int productQuantity; if (OrderCart.Exists(sli => sli.affectedInventoryLineItem == selectedLineItem)) { productQuantity = OrderCart.FindLast(sli => sli.affectedInventoryLineItem == selectedLineItem).GetNewQuantityOfAffectedInventoryLineItem(); } else { productQuantity = selectedLineItem.ProductQuantity; } return(productQuantity); }
public CustomerLineItemQuantitySubMenu(ref InventoryLineItem selectedLineItem, ref OrderBuilder orderBuilder, ref IRepository repo) : base(ref repo) { Log.Logger.Information("Instantiated Customer Line Item Quantity Selection Submenu."); SelectedLineItem = selectedLineItem; selectedProduct = selectedLineItem.Product; OrderBuilder = orderBuilder; StagedLineItem stagedLineItem = OrderBuilder.GetStagedLineItemForAffectedLineItemIfItExists(selectedLineItem); if (stagedLineItem != null) { maxQuantity = stagedLineItem.GetNewQuantityOfAffectedInventoryLineItem(); } else { maxQuantity = selectedLineItem.ProductQuantity; } }
public void RemoveInventoryLineItemFromLocation(InventoryLineItem lineItem) { context.InventoryLineItems.Remove(lineItem); }
public void RemoveInventoryLineItem(InventoryLineItem lineItem) { context.InventoryLineItems.Remove(lineItem); }
public void UpdateInventoryLineItem(InventoryLineItem lineItem) { context.InventoryLineItems.Update(lineItem); }
public void AddInventoryLineItem(InventoryLineItem lineItem) { context.InventoryLineItems.Add(lineItem); }
public InventoryLineItem DeleteInventoryLineItem(InventoryLineItem inventoryLineItem2BDeleted) { _context.InventoryLineItems.Remove(_mapper.ParseInventoryLineItem(inventoryLineItem2BDeleted)); _context.SaveChanges(); return(inventoryLineItem2BDeleted); }
// Add to CustomerOrderLineItem public void AddItemToCart(Customer customer, InventoryLineItem item, int quantity) { CustomerOrderLineItem _coli = new CustomerOrderLineItem(); }
public void RemoveInventoryLineItem(InventoryLineItem lineItem) { throw new NotImplementedException(); }