public List <OrderItemViewModel> GetProductList() { using (ShopDBEntities db = new ShopDBEntities()) { var ListProduct = db.Product.ToList(); List <OrderItemViewModel> ListView = new List <OrderItemViewModel>(); foreach (var item in ListProduct) { OrderItemViewModel Model = new OrderItemViewModel(); Model.ProductId = item.Id; Model.ProductName = item.ProductName; ListView.Add(Model); } return(ListView); } }
private decimal CalculateAmount(OrderItemViewModel orderItem, Guid customerId) { var customer = _context.Customers .Include(t => t.CustomPrices.Select(u => u.Product)) .Single(t => t.Id == customerId); var customPrice = customer.CustomPrices .SingleOrDefault(t => t.Product.Id == orderItem.ProductId); if (customPrice == null) { return(_context.Products .Single(t => t.Id == orderItem.ProductId) .PricePerKilo *orderItem.Quantity *orderItem.KilosNeeded); } return(customPrice.Price * orderItem.Quantity * orderItem.KilosNeeded); }
// POST: api/OrderItems public async Task <HttpResponseMessage> Post([FromBody] OrderItemViewModel item) { HttpResponseMessage response; try { await _orderItemService.AddToOrder(_mapper.Map <OrderItemDto>(item)); response = Request.CreateResponse(HttpStatusCode.OK); } catch (Exception e) { Debug.WriteLine(e); response = Request.CreateResponse(HttpStatusCode.InternalServerError); } return(response); }
public IActionResult Detail(long id) { var order = orderRepository .Query() .Include(x => x.ShippingAddress).ThenInclude(x => x.Address).ThenInclude(x => x.District).ThenInclude(x => x.StateOrProvince) .Include(x => x.OrderItems).ThenInclude(x => x.Product).ThenInclude(x => x.ThumbnailImage) .Include(x => x.OrderItems).ThenInclude(x => x.ProductVariation).ThenInclude(x => x.OptionCombinations).ThenInclude(x => x.Option) .Include(x => x.CreatedBy) .FirstOrDefault(x => x.Id == id); if (order == null) { return(new NotFoundResult()); } var model = new OrderDetailViewModel { Id = order.Id, CreatedOn = order.CreatedOn, CustomerName = order.CreatedBy.FullName, SubTotal = order.SubTotal, ShippingAddress = new ShippingAddressViewModel { AddressLine1 = order.ShippingAddress.Address.AddressLine1, AddressLine2 = order.ShippingAddress.Address.AddressLine2, ContactName = order.ShippingAddress.Address.ContactName, DistrictName = order.ShippingAddress.Address.District.Name, StateOrProvinceName = order.ShippingAddress.Address.StateOrProvince.Name, Phone = order.ShippingAddress.Address.Phone }, OrderItems = order.OrderItems.Select(x => new OrderItemViewModel { Id = x.Id, ProductName = x.Product.Name, ProductPrice = x.ProductPrice, ProductImage = mediaService.GetThumbnailUrl(x.Product.ThumbnailImage), Quantity = x.Quantity, VariationOptions = OrderItemViewModel.GetVariationOption(x.ProductVariation) }).ToList() }; return(Json(model)); }
public IActionResult AddSameItemOnceToBasket(string id, string type) { var productId = GuidEncoder.Decode(id).ToString(); var orderItems = _orderItemBasket.OrderItems; var orderItemsSize = orderItems.Count; var orderItem = new OrderItemViewModel(); foreach (var item in orderItems) { var sameProductId = string.Compare(item.ProductId, productId, true); var sameType = string.Compare(item.ProductType, type, true); if (sameProductId + sameType == 0) { item.Quantity += 1; item.TotalQuantityPrice = item.Quantity * item.Product.Price; } } return(RedirectToAction(nameof(ListOfBasketItems))); }
public async Task <ActionResult <OrderItemViewModel> > Post([FromBody] OrderItemViewModel order) { try { await _orderService.OrderAsync(order.ProductId, order.Quantity); return(Ok()); } catch (InvalidOperationException e) { return(BadRequest(new ApiErrorViewModel((int)HttpStatusCode.InternalServerError, HttpStatusCode.InternalServerError.ToString(), e.Message))); } catch (ProductNotFountException e) { return(NotFound(new ApiErrorViewModel((int)HttpStatusCode.NotFound, HttpStatusCode.NotFound.ToString(), e.Message))); } }
public IActionResult Payment() { OrderItemViewModel model = new OrderItemViewModel(); var basketProductCookie = Request.Cookies["InCard"]; if (basketProductCookie != null) { var productIds = basketProductCookie; var addingproductIds = basketProductCookie.Split('-').Select(x => int.Parse(x)).ToList(); model.ProductsCheckout = _remindb.Products.Include(m => m.Images) .Include(x => x.CategoryMarka) .Include(o => o.CategoryMarka.Category) .Include(a => a.CategoryMarka.Marka) .Where(pr => addingproductIds.Contains(pr.Id)).ToList(); model.ProductsCheckoutId = addingproductIds; } return(View(model)); }
public IActionResult OrderHistory() { var claimsIdentity = (ClaimsIdentity)User.Identity; var claim = claimsIdentity.FindFirst(ClaimTypes.NameIdentifier); List <OrderItemViewModel> orderItemVMList = new List <OrderItemViewModel>(); List <Order> orderList = _orderRepository.GetOrdersByUserId(claim.Value).ToList(); var orderItems = _orderItemRepository.GetAll(); foreach (var order in orderList) { OrderItemViewModel orderItemVM = new OrderItemViewModel { Order = order, OrderItems = orderItems.Where(o => o.OrderId.Equals(order.Id)).ToList() }; } return(View(orderItemVMList)); }
public List <OrderItemViewModel> GetOrderItem(int id) { using (ShopDBEntities db = new ShopDBEntities()) { var ListOrderItem = (from p in db.OrderItem where p.OrderId.Equals(id) select p).ToList(); List <OrderItemViewModel> ListView = new List <OrderItemViewModel>(); foreach (var orderItem in ListOrderItem) { OrderItemViewModel Model = new OrderItemViewModel(); Model.Id = orderItem.Id; Model.OrderId = orderItem.OrderId; Model.ProductId = orderItem.ProductId; Model.ProductName = orderItem.Product.ProductName; Model.UnitPrice = orderItem.UnitPrice; Model.Quantity = orderItem.Quantity; ListView.Add(Model); } return(ListView); } }
public ActionResult Details(int id) { var orderItems = orderService.GetAllOrderItems().Where(s => s.OrderId == id).AsEnumerable(); List <OrderItemViewModel> orderItemModels = new List <OrderItemViewModel>(); foreach (var orderItem in orderItems) { ProductModel productModel = productService.GetProduct(orderItem.ProductId); OrderItemViewModel _orderItem = new OrderItemViewModel { Product = new ProductViewModel(productModel), Amount = orderItem.Amount, Sum = orderItem.Sum, OrderId = orderItem.OrderId, }; orderItemModels.Add(_orderItem); } return(Json(orderItemModels, JsonRequestBehavior.AllowGet)); }
public void AddOrder(OrderModel model) { if (orderModels.ContainsKey(model.Id)) { foreach (OrderItemModel itemModel in orderModels[model.Id].OrderItems.Values) { if (!model.OrderItems.ContainsKey(itemModel.Id)) { //Delete itemModelView adapter.RemoveItem(itemModel.Id); adapter.NotifyDataSetChanged(); } } orderModels.Remove(model.Id); } if (model.OrderItems.Values.Where(i => i.State != State.Completed).Count() != 0) { orderModels.Add(model.Id, model); } foreach (OrderItemModel itemModel in model.OrderItems.Values) { if (adapter.Items.Where(a => a.Id == itemModel.Id).Count() != 0) { OrderItemViewModel item = adapter.Items.Where(a => a.Id == itemModel.Id).Single(); item.Name = model.Name; item.Description = itemModel.DisplayName; item.State = itemModel.State; adapter.NotifyDataSetChanged(); } else if (itemModel.State != State.Completed) { OrderItemViewModel viewModel = new OrderItemViewModel(itemModel.Id, itemModel.OrderId, model.Name, itemModel.DisplayName, itemModel.State, itemModel.ComponentModels.Count > 0, itemModel.InOutStatus); adapter.AddItem(viewModel); adapter.NotifyDataSetChanged(); } } }
//[Route("AddToCart")] public IHttpActionResult Add(OrderItemViewModel orderitem) { if (!ModelState.IsValid) { return(BadRequest("Invalid data.")); } Order order; if (orderitem.OrderId == 0) { order = new Order() { OrderTime = DateTime.Now, CustomerId = orderitem.CustomerId, DeliveryTime = DateTime.Now, PaymentMethod = "Test", PaymentDone = true, DeliveryPlace = "test", OrderStatus = "TEEST" }; appdb.Orders.Add(order); appdb.SaveChanges(); } else { order = appdb.Orders.FirstOrDefault(i => i.Id == orderitem.OrderId); } var m = appdb.OrderItems.Add(new OrderItem() { Id = orderitem.Id, Quantity = orderitem.Quantity, MenuItemId = orderitem.MenuItemId, OrderId = order.Id, }); appdb.SaveChanges(); return(Ok()); }
public static OrderItemViewModel OrderItemToViewModel(OrderItem item) { OrderItemViewModel toReturn = new OrderItemViewModel() { ID = item.ID, Price = item.Price, ProductID = item.ProductID, Quantity = item.Quantity, Status = item.Status }; StoreContext db = new StoreContext(); Product product = db.Products.SingleOrDefault(x => x.ID.ToString() == item.ProductID); string name = product.Name; toReturn.Name = name; return(toReturn); }
public async Task <IActionResult> StoreHistory(int?id) { /// <summary> /// The store order history page /// </summary> if (id == null) { return(NotFound()); } int thisLocId = (int)id; if (!UtilMethods.LogInCheck(_cache)) { return(Redirect("/Login")); } var thisLocation = await _context.Locations .FirstOrDefaultAsync(m => m.LocationId == thisLocId); if (thisLocation == null) { return(NotFound()); } var foundOrderItems = from thisTableItem in _context.OrderItems where thisTableItem.LocationId == thisLocation.LocationId select thisTableItem; List <OrderItem> theseOrderItems = foundOrderItems.ToList <OrderItem>(); List <OrderItemViewModel> theseOrderItemViewModels = new List <OrderItemViewModel>(); foreach (OrderItem thisOrderItem in theseOrderItems) { Customer thisCustomer = await _context.Customers .FirstOrDefaultAsync(m => m.CustomerId == thisOrderItem.CustomerId); OrderItemViewModel thisOrderItemViewModel = UtilMethods.BuildOrderItemViewModelFromCustOrder(thisCustomer, thisOrderItem, _context); theseOrderItemViewModels.Add(thisOrderItemViewModel); } ViewData["storeaddress"] = thisLocation.LocationAddress; ViewData["cartcount"] = UtilMethods.GetCartCount(_cache); return(View(theseOrderItemViewModels)); }
public async Task <IActionResult> AddItem(string id, string type) { var path = string.Format("{0}/{1}", Products_Base_Address, GuidEncoder.Decode(id)); var product = PopulateUriKey( _mapper.Map <ProductViewModel>( await _apiClient.GetAsync <ProductDto>(path))); var pricePath = string.Format("{0}/{1}", SinglePriceByType_Base_Address, type); var price = _mapper.Map <PricesViewModel>( await _apiClient.GetAsync <PricesDto>(pricePath)); product.Prices.Add(price); product.Type = type; product.Price = price.Price; var oi = await Task.Run(() => { var orderItem = new OrderItemViewModel() { Product = product, Quantity = 1, ProductType = product.Type, ProductDescription = product.Description, UriKey = id }; orderItem.ProductName = product.Name; orderItem.TotalQuantityPrice = orderItem.Quantity *product.Price; orderItem.Product = product; orderItem.UnitPrice = product.Price; orderItem.Description = product.Description; orderItem.ProductId = product.ProductId; return(orderItem); //_orderItemBasket.OrderItems.Add(orderItem); }); _orderItemBasket.OrderItems.Add(oi); return(RedirectToAction(nameof(ListOfBasketItems))); }
public IHttpActionResult Get(int id) { var orderitem = appdb.OrderItems.FirstOrDefault(o => o.Id == id); if (orderitem == null) { return(NotFound()); } OrderItemViewModel model = new OrderItemViewModel() { Id = orderitem.Id, Quantity = orderitem.Quantity, MenuItemId = orderitem.MenuItemId, OrderId = orderitem.OrderId, Order = new OrderViewModel() { Id = orderitem.Order.Id, OrderTime = orderitem.Order.OrderTime, OrderStatus = orderitem.Order.OrderStatus, DeliveryTime = orderitem.Order.DeliveryTime, DeliveryPlace = orderitem.Order.DeliveryPlace, PaymentMethod = orderitem.Order.PaymentMethod, PaymentDone = orderitem.Order.PaymentDone, customerid = orderitem.Order.CustomerId }, MenuItem = new MenuItemViewModel() { Id = orderitem.MenuItem.Id, Name = orderitem.MenuItem.Name, Description = orderitem.MenuItem.Description, Price = orderitem.MenuItem.Price, Type = orderitem.MenuItem.Type, CategoryId = orderitem.MenuItem.CategoryId } }; return(Ok(new { orderitem = model })); }
public ActionResult UpdateOrder(int ItemCode, int Qty) { try { if (Qty == 0) { OrderItemViewModel cvm = ((List <OrderItemViewModel>)Session["FoodItems"]).FirstOrDefault(i => i.Item.Item_Code == ItemCode); ((List <OrderItemViewModel>)Session["FoodItems"]).Remove(cvm); } else { ((List <OrderItemViewModel>)Session["FoodItems"]).FirstOrDefault(i => i.Item.Item_Code == ItemCode).Qty = Qty; ((List <OrderItemViewModel>)Session["FoodItems"]).FirstOrDefault(i => i.Item.Item_Code == ItemCode).SubTotal = (((List <OrderItemViewModel>)Session["FoodItems"]).FirstOrDefault(i => i.Item.Item_Code == ItemCode).Item.Portion_Price ?? 0) * Qty; // Session["Total"] = ((int)Session["Total"]) + (((List<OrderItemViewModel>)Session["FoodItems"]).FirstOrDefault(i => i.Item.Item_Code == ItemCode).Item.Portion_Price ?? 0) * Qty; } return(RedirectToAction("OrderIndex")); } catch (Exception ez) { return(View()); } }
public OrderItem Map(OrderItemViewModel order_item_vm) { var address_proxy = _service_fact.CreateClient <IAddressService>(); var product_proxy = _service_fact.CreateClient <IProductService>(); var order_proxy = _service_fact.CreateClient <IOrderService>(); var employee_service = _service_fact.CreateClient <IEmployeeService>(); var type_service = _service_fact.CreateClient <ITypeService>(); var orderItem = new OrderItem() { OrderItemKey = order_item_vm.OrderItemKey, OrderKey = order_item_vm.OrderKey, OrderItemSeq = order_item_vm.OrderItemSeq, ProductKey = order_item_vm.ProductKey, ProductName = order_item_vm.ProductName, ProductDesc = order_item_vm.ProductDesc, OrderItemQuantity = order_item_vm.Quantity, //OrderItemShipToAddress = order_item_data.ShiptoAddrKey, OrderItemShipToAddress = address_proxy.GetAddress(order_item_vm.OrderItemShipAddress.AddressKey), //OrderItemBillToAddress = order_item_data.BilltoAddrKey, OrderItemBillToAddress = address_proxy.GetAddress(order_item_vm.OrderItemBillAddress.AddressKey), //OrderItemShipDate = order_item_vm.OrderItemShipDate, //OrderItemCompleteDate = order_item_vm.OrderItemCompleteDate, ItemPricePer = order_item_vm.OrderItemPrice, OrderItemLineSum = order_item_vm.OrderLineTotal, OrderItemStatus = (QIQOOrderItemStatus)type_service.GetOrderItemStatusList() .Where(key => key.OrderItemStatusName == order_item_vm.OrderItemStatus) .FirstOrDefault().OrderItemStatusKey, //Product OrderItemProduct = product_proxy.GetProduct(order_item_vm.ProductKey), //Account Rep AccountRep = employee_service.GetAccountRepsByCompany(1)[0], //Sales Rep SalesRep = employee_service.GetSalesRepsByCompany(1)[0] }; return(orderItem); }
public IActionResult Add(int id) { Customer customer = Data.Customers.FirstOrDefault(x => x.Orders.Any(y => y.Id == id)); if (customer == null) { return(NotFound()); } Order order = customer.Orders.FirstOrDefault(x => x.Id == id); if (order == null) { return(NotFound()); } OrderItem orderItem = new OrderItem(order.Id); OrderItemViewModel orderItemViewModel = OrderItem.ToViewModel(orderItem); ViewBag.PizzaSizesForSelect = Data.PizzaSizesToSelectListItems(); return(View(orderItemViewModel)); }
public OrderViewModel PrepareSessionCartOrder() { var cart = _cartService.Cart; var cartItemIds = cart.Lines.Select(cl => cl.Id); var catalogItems = _catalogService.GetAll() .Where(ci => cartItemIds.Any(id => id == ci.Id)); var orderViewModel = new OrderViewModel(); orderViewModel.CreationDate = DateTime.Now.ToUniversalTime(); orderViewModel.ItemsPreview = new OrderItemsPreviewViewModel(); // Order items from db foreach (var catalogItem in catalogItems) { var orderItem = new OrderItemViewModel { CreationDate = DateTime.Now.ToUniversalTime(), Name = catalogItem.Name, ItemId = catalogItem.Id, Quantity = cart.Lines.Where(cl => cl.Id == catalogItem.Id).First().Quantity }; if (catalogItem.DiscountId.HasValue) { var discount = _discountService.GetById(catalogItem.DiscountId.Value); orderItem.UnitPrice = discount.NewValue; } else { orderItem.UnitPrice = catalogItem.Price; } orderViewModel.ItemsPreview.Items.Add(orderItem); } return(orderViewModel); }
public List <OrderItemViewModel> UpdateList(OrderItemObject Obj) { using (ShopDBEntities db = new ShopDBEntities()) { if (Obj.ListOrderItem.Any(x => x.ProductId.Equals(Obj.OrderItem.ProductId))) { Obj.ListOrderItem.FirstOrDefault(x => x.ProductId.Equals(Obj.OrderItem.ProductId)).Quantity += Obj.OrderItem.Quantity; } else { OrderItemViewModel Model = new OrderItemViewModel(); var product = GetProductById(Obj.OrderItem.ProductId); Model.Id = Obj.OrderItem.Id + Obj.ListOrderItem.Count; Model.ProductId = Obj.OrderItem.ProductId; Model.UnitPrice = (decimal)product.UnitPrice; Model.ProductName = product.ProductName; Model.Quantity = Obj.OrderItem.Quantity; Obj.ListOrderItem.Add(Model); } return(Obj.ListOrderItem); } }
public IActionResult History() { /// <summary> /// User order history page /// </summary> if (!UtilMethods.LogInCheck(_cache)) { return(Redirect("/Login")); } Customer thisCustomer = (Customer)_cache.Get("thisCustomer"); var foundOrderItems = _context.OrderItems.Where(m => m.CustomerId == thisCustomer.CustomerId); List <OrderItem> theseOrderItems = foundOrderItems.ToList <OrderItem>(); List <OrderItemViewModel> theseOrderItemViewModels = new List <OrderItemViewModel>(); foreach (OrderItem thisOrderItem in theseOrderItems) { OrderItemViewModel thisOrderItemViewModel = UtilMethods.BuildOrderItemViewModelFromCustOrder(thisCustomer, thisOrderItem, _context); theseOrderItemViewModels.Add(thisOrderItemViewModel); } ViewData["userName"] = $"{thisCustomer.FirstName} {thisCustomer.LastName}"; ViewData["cartcount"] = UtilMethods.GetCartCount(_cache); return(View(theseOrderItemViewModels)); }
public static OrderItemViewModel BuildOrderItemViewModelFromCustOrder(Customer thisCustomer, OrderItem thisOrderItem, DbContextClass context) { /// <summary> /// Builds an order item view model from customer and order item /// </summary> Product thisProduct = UtilMethods.GetProductById(thisOrderItem.ProductId, context); Location thisLocation = UtilMethods.GetLocationById(thisOrderItem.LocationId, context); //string thisAddress = thisLocation.LocationAddress; double thisPrice = UtilMethods.TrimPriceDigits(thisOrderItem.TotalPriceWhenOrdered); OrderItemViewModel thisOrderItemViewModel = new OrderItemViewModel( thisCustomer.CustomerId, thisLocation.LocationId, thisProduct.ProductId, $"{thisCustomer.FirstName} {thisCustomer.LastName}", thisProduct.Name, thisOrderItem.OrderCount, thisPrice, thisLocation.LocationAddress, thisOrderItem.DateOrdered ); return(thisOrderItemViewModel); }
public void BuildOrderItemViewModelFromCustOrderWorks() { // Act //// Service setup var services = new ServiceCollection(); services.AddMemoryCache(); services.AddDbContext <DbContextClass>(options => options.UseInMemoryDatabase("testDb")); var serviceProvider = services.BuildServiceProvider(); //// DbContext setup DbContextClass testContext = serviceProvider.GetService <DbContextClass>(); //// DbContext populating Customer testCustomer = new Customer(); testCustomer.FirstName = "fn"; testCustomer.LastName = "ln"; Location testLocation = new Location(); StockItem testStockItem = new StockItem(); testStockItem.DiscountPercent = 50; Product testProduct = new Product(); OrderItem testOrderItem = new OrderItem(); testOrderItem.TotalPriceWhenOrdered = 3; testProduct.BasePrice = 6; testContext.Add(testProduct); testContext.Add(testLocation); testContext.SaveChanges(); // Arrange OrderItemViewModel testOrderItemViewModel = RevatureP1.UtilMethods.BuildOrderItemViewModelFromCustOrder( testCustomer, testOrderItem, testContext); var resultVal = testOrderItemViewModel.CustomerName; var expectedVal = "fn ln"; //Assert Assert.Equal(expectedVal, resultVal); }
public async Task <List <IOrderItemViewModel> > GetOrderItemViewForOrderNum(int OrderNum) { List <IOrderItemViewModel> items = new List <IOrderItemViewModel>(); if (_isDataInitialized == false) { InitializeData(); } foreach (IOrderModel Order in _orders) { if (Order.OrderNum == OrderNum) { foreach (IOrderItemModel item in Order.OrderItems) { IOrderItemViewModel itemView = new OrderItemViewModel(); itemView.OrderNum = OrderNum; itemView.ItemNum = item.ItemNum; itemView.Quantity = item.Quantity; itemView.CategoryNum = item.CategoryNum; foreach (IItemCategoryModel catModel in _itemCategories) { if (item.CategoryNum == catModel.CategoryNum) { itemView.CategoryDescription = catModel.CategoryDescription; } } items.Add(itemView); } } } await Task.Delay(0); return(items); }
private JsonResult UpdateItemQuantity(OrderItemViewModel orderItemViewModel) { int?orderID = -1; if (orderItemViewModel.OrderID == -1) { string ip = Request.ServerVariables["REMOTE_ADDR"]; orderID = orderRepository.createOrderShell(ip); } else { orderID = orderItemViewModel.OrderID; } int?orderItemID = orderRepository.UpdateItemQuantity(orderItemViewModel.ProductID, (int)orderID, (uint)orderItemViewModel.Quantity); orderRepository.SaveChanges(); return(Json(new { orderItemID = orderItemID ?? -1, ordID = orderID ?? -1 })); }
public List <OrderItemViewModel> GetAllOrderForClient(int infoId) { var query = context.Orders.Include(x => x.Product).Include(x => x.Category).Where(i => i.InfoId == infoId && i.State == 1 && i.IsClientState == 1); List <OrderItemViewModel> items = new List <OrderItemViewModel>(); foreach (var item in query) { OrderItemViewModel itemViewModel = new OrderItemViewModel(); itemViewModel.OrderItemId = item.Id; itemViewModel.ProductName = item.Product.ProductTitle; itemViewModel.ProductId = item.ProductId; itemViewModel.CategoryName = item.Category.Name; itemViewModel.CategoryId = item.CategoryId; itemViewModel.Quantity = item.Quantity; itemViewModel.OrderId = item.OrderId; itemViewModel.ProductPrice = item.ProductPrice; itemViewModel.OrderDate = item.OrderDate; items.Add(itemViewModel); } return(items); }
public IActionResult Post([FromBody] OrderItemViewModel model) { try { if (ModelState.IsValid) { var newItem = _mapper.Map <OrderItemViewModel, OrderItem>(model); var addedOrderItem = _orderItemRepo.AddOrderItem(newItem); return(Created($"/api/orders/{addedOrderItem.OrderId}/items/{addedOrderItem.Id}", _mapper.Map <OrderItem, OrderItemViewModel>(addedOrderItem))); } else { return(BadRequest(ModelState)); } } catch (Exception ex) { _logger.LogError($"Failed to get order: {ex}"); return(BadRequest("Failed to get order")); } }
public IActionResult AddOrderItem(int id) { if (!ModelState.IsValid) { throw new Exception("Controller Error!"); } var result = new OrderItemViewModel { OrderId = id, Quantity = 1 }; var currentOrder = _orderRepo.GetOrderById(id); var currentInventory = _storeRepo.GetInventoryByStore(currentOrder.Store); var products = _productRepo.GetAllProducts(); foreach (var product in products) { if (currentInventory.Any(a => (a.ProductName == product.ProductName && a.Stock > 0))) { result.Products.Add(product); } } return(View(result)); }
public void GetCartCountWorks() { // Act //// Service setup var services = new ServiceCollection(); services.AddMemoryCache(); var serviceProvider = services.BuildServiceProvider(); //// Cache setup var memoryCache = serviceProvider.GetService <IMemoryCache>(); IMemoryCache _cache = RevatureP1.UtilMethods.InitializeCacheIfNeeded(memoryCache); //// Cache populating OrderItemViewModel testOrderItemViewModel = new OrderItemViewModel(); List <OrderItemViewModel> thisCart = (List <OrderItemViewModel>)memoryCache.Get("customerCart"); thisCart.Add(testOrderItemViewModel); memoryCache.Set("customerCart", thisCart); // Arrange var resultVal = RevatureP1.UtilMethods.GetCartCount(memoryCache); var expectedVal = 1; //Assert Assert.Equal(expectedVal, resultVal); }