public IActionResult TypeSelected(Models.OrderItem ai) { var dbPizza = client.GetAllPizzas().FirstOrDefault(p => p.PizzaType == ai.PizzaType); if (dbPizza is null) { return(BadRequest("Somehow you picked a Type of Pizza that doesn't exist in the DB")); } var sessionOrder = Utils.GetCurrentOrder(HttpContext.Session); // just copy over the entire pizza // this ensures we have at the bare minimum a basic, working pizza var lastPizza = sessionOrder.Pizzas.Last(); lastPizza.Name = dbPizza.Name; lastPizza.PizzaType = dbPizza.PizzaType; lastPizza.Crust = dbPizza.Crust; lastPizza.Size = dbPizza.Size; lastPizza.Toppings = dbPizza.Toppings; if (lastPizza.PizzaType == Models.PIZZA_TYPE.Custom) { // make sure we start off with no toppings lastPizza.Toppings.Clear(); } Utils.SaveOrder(HttpContext.Session, sessionOrder); return(RedirectToAction("SelectSize", "Pizza")); }
public async Task <IActionResult> UpdateOrderItem(int orderItemId, [FromBody] Models.OrderItem orderItemMod) { if (orderItemMod == null) { return(BadRequest()); } var orderItemEnt = await _ordService.GetOrderItemAsync(orderItemId); if (orderItemEnt == null) { return(NotFound(new { Error = $"An with Id '{orderItemId}' could not be found." })); } TryValidateModel(orderItemMod); // Add validation if (!ModelState.IsValid) { return(new UnprocessableEntityObjectResult(ModelState)); } _ordMapper.MapOrderItemModelToEntity(orderItemMod, orderItemEnt); _ordService.UpdateOrderItem(orderItemEnt); if (!await _ordService.SaveOrderItemChangesAsync()) { throw new Exception($"Error updating order item with Id '{orderItemEnt.Id}'."); } return(NoContent()); }
public async Task <IActionResult> AddOrderItem([FromBody] Models.OrderItem orderItemMod) { if (orderItemMod == null) { return(BadRequest()); } if (!ModelState.IsValid) { return(new UnprocessableEntityObjectResult(ModelState)); } // Map restaurant model to entity. var orderInfoEnt = _ordMapper.OrderItemModelToEntity(orderItemMod); _ordService.AddOrderItem(orderInfoEnt); if (!await _ordService.SaveOrderItemChangesAsync()) { throw new Exception($"Could not add item to order with Id '{orderItemMod.OrderId}'."); } // Map newly saved restaurant back to model. orderItemMod = _ordMapper.OrderItemEntityToModel(orderInfoEnt); return(CreatedAtRoute("GetOrderItem", new { orderId = orderItemMod.Id }, orderItemMod)); }
private OrderOneS GetOrderItems(Order order, OrderOneS orderOneS) { var orderItems = order.OrderItems; foreach (var orderItem in orderItems) { var parentProduct = _productService.GetProductById(orderItem.Product.ParentGroupedProductId); var manufacturer = _productService.GetProductById(parentProduct.ParentGroupedProductId); var orderItemOneS = new Models.OrderItem(); orderItemOneS.Id = orderItem.OrderId; orderItemOneS.StateId = ""; //TODO:вопрос orderItemOneS.Sum = orderItem.PriceInclTax; orderItemOneS.UnitTitle = "шт"; //TODO: вопрос orderItemOneS.Quantity = orderItem.Quantity; orderItemOneS.Price = orderItem.UnitPriceExclTax; orderItemOneS.Title = orderItem.Product.Name; orderItemOneS.Model = orderItem.Product.Name; orderItemOneS.ModelId = orderItem.Product.Sku; orderItemOneS.Product = parentProduct.Name; orderItemOneS.ProductId = parentProduct.Sku; orderItemOneS.ProductMarkaId = manufacturer.Sku; var variantAttributeCombination = orderItem.Product.ProductVariantAttributeCombinations.FirstOrDefault(); if (variantAttributeCombination != null) { orderItemOneS.StorageId = variantAttributeCombination.Sku; } orderOneS.OrderItems.Add(orderItemOneS); } return(orderOneS); }
public ActionResult EditSyrups(ICollection <MenuItem> syrups) { Models.Customer customer = GetLoggedInCustomer(); Models.OrderItem orderItem = GetOrderItem(customer.CurrentOrderItemId); List <Syrup> syrupList = new List <Syrup>(); for (int i = 0; i < syrups.Count(); i++) { MenuItem setSyrup = syrups.ElementAt(i); if (setSyrup.Quantity == null) { setSyrup.Quantity = 0; } Syrup newSyrup = new Syrup(); newSyrup.SyrupType = setSyrup.Name; newSyrup.SyrupPumps = setSyrup.Quantity; newSyrup.OrderItemId = orderItem.OrderItemId; newSyrup.Price = (setSyrup.Price * setSyrup.Quantity); syrupList.Add(null); syrupList[i] = new Syrup(); syrupList[i].SyrupType = newSyrup.SyrupType; syrupList[i].SyrupPumps = newSyrup.SyrupPumps; syrupList[i].OrderItemId = newSyrup.OrderItemId; syrupList[i].Price = newSyrup.Price; db.SaveChanges(); } orderItem.Syrups = syrupList; db.SaveChanges(); return(RedirectToAction("ReviewOrder", new { id = orderItem.OrderItemId })); }
public ActionResult RemoveOrderItem(int id) { Models.OrderItem orderItem = db.OrderItems.FirstOrDefault(o => o.OrderItemId == id); db.OrderItems.Remove(orderItem); db.SaveChanges(); return(RedirectToAction("ReviewOrderBeforeCheckout")); }
public IActionResult SizeSelected(Models.OrderItem selection) { var dbSize = client.GetAllSizes().FirstOrDefault(s => s.SizeType == selection.SizeType); if (dbSize is null) { return(BadRequest("Somehow you got a null crust?")); } var sessionOrder = Utils.GetCurrentOrder(HttpContext.Session); var addedPizza = sessionOrder.Pizzas.Last(); addedPizza.Size = dbSize; Utils.SaveOrder(HttpContext.Session, sessionOrder); if (addedPizza.PizzaType != Models.PIZZA_TYPE.Custom) { return(RedirectToAction("CheckConstraints", "Order")); } else { return(RedirectToAction("Menu", "Pizza")); } }
public ActionResult ReviewOrderByEmployee(int id) { Models.OrderItem orderItem = db.OrderItems.FirstOrDefault(o => o.OrderItemId == id); ICollection <Creamer> creamerList = db.Creamers.Where(c => c.OrderItemId == orderItem.OrderItemId && c.Splashes != 0).ToList(); ViewBag.creamers = creamerList; ICollection <Drizzle> drizzleList = db.Drizzles.Where(c => c.OrderItemId == orderItem.OrderItemId && c.Drizzles != 0).ToList(); ViewBag.drizzles = drizzleList; ICollection <Powder> powderList = db.Powders.Where(c => c.OrderItemId == orderItem.OrderItemId && c.Scoops != 0).ToList(); ViewBag.powders = powderList; ICollection <Sauce> sauceList = db.Sauces.Where(c => c.OrderItemId == orderItem.OrderItemId && c.SaucePumps != 0).ToList(); ViewBag.sauces = sauceList; ICollection <Shot> shotList = db.Shots.Where(c => c.OrderItemId == orderItem.OrderItemId && c.Shots != 0).ToList(); ViewBag.shots = shotList; ICollection <Sweetener> sweetenerList = db.Sweeteners.Where(c => c.OrderItemId == orderItem.OrderItemId && c.Scoops != 0).ToList(); ViewBag.sweeteners = sweetenerList; ICollection <Syrup> syrupList = db.Syrups.Where(c => c.OrderItemId == orderItem.OrderItemId && c.SyrupPumps != 0).ToList(); ViewBag.syrups = syrupList; ICollection <Toppings> toppingsList = db.Toppings.Where(c => c.OrderItemId == orderItem.OrderItemId && c.ToppingsAmmount != 0).ToList(); ViewBag.toppings = toppingsList; ViewBag.price = orderItem.Price; return(View(orderItem)); }
public ActionResult ReviewSelectedItemByEmployee(int id) { Models.OrderItem orderItem = db.OrderItems.FirstOrDefault(o => o.OrderItemId == id); Models.Order order = db.Orders.FirstOrDefault(o => o.OrderId == orderItem.OrderId); return(RedirectToAction("ReviewOrderByEmployee", new { id = id })); }
public ActionResult EditPowders(ICollection <MenuItem> powders) { Models.Customer customer = GetLoggedInCustomer(); Models.OrderItem orderItem = GetOrderItem(customer.CurrentOrderItemId); List <Powder> powderList = new List <Powder>(); for (int i = 0; i < powders.Count(); i++) { MenuItem setPowder = powders.ElementAt(i); if (setPowder.Quantity == null) { setPowder.Quantity = 0; } Powder newPowder = new Powder(); newPowder.PowderType = setPowder.Name; newPowder.Scoops = setPowder.Quantity; newPowder.OrderItemId = orderItem.OrderItemId; newPowder.Price = (setPowder.Price * setPowder.Quantity); powderList.Add(null); powderList[i] = new Powder(); powderList[i].PowderType = newPowder.PowderType; powderList[i].Scoops = newPowder.Scoops; powderList[i].OrderItemId = newPowder.OrderItemId; powderList[i].Price = newPowder.Price; db.SaveChanges(); } orderItem.Powders = powderList; db.SaveChanges(); return(RedirectToAction("ReviewOrder", new { id = orderItem.OrderItemId })); }
public ActionResult EditToppings(ICollection <MenuItem> toppings) { Models.Customer customer = GetLoggedInCustomer(); Models.OrderItem orderItem = GetOrderItem(customer.CurrentOrderItemId); List <Toppings> toppingsList = new List <Toppings>(); for (int i = 0; i < toppings.Count(); i++) { MenuItem setToppings = toppings.ElementAt(i); if (setToppings.Quantity == null) { setToppings.Quantity = 0; } Toppings newToppings = new Toppings(); newToppings.ToppingsType = setToppings.Name; newToppings.ToppingsAmmount = setToppings.Quantity; newToppings.OrderItemId = orderItem.OrderItemId; newToppings.Price = (setToppings.Price * setToppings.Quantity); toppingsList.Add(null); toppingsList[i] = new Toppings(); toppingsList[i].ToppingsType = newToppings.ToppingsType; toppingsList[i].ToppingsAmmount = newToppings.ToppingsAmmount; toppingsList[i].OrderItemId = newToppings.OrderItemId; toppingsList[i].Price = newToppings.Price; db.SaveChanges(); } orderItem.Toppings = toppingsList; db.SaveChanges(); return(RedirectToAction("ReviewOrder", new { id = orderItem.OrderItemId })); }
public ActionResult EditDrizzles(ICollection <MenuItem> drizzles) { Models.Customer customer = GetLoggedInCustomer(); Models.OrderItem orderItem = GetOrderItem(customer.CurrentOrderItemId); List <Drizzle> drizzleList = new List <Drizzle>(); for (int i = 0; i < drizzles.Count(); i++) { MenuItem setDrizzle = drizzles.ElementAt(i); if (setDrizzle.Quantity == null) { setDrizzle.Quantity = 0; } Drizzle newDrizzle = new Drizzle(); newDrizzle.DrizzleType = setDrizzle.Name; newDrizzle.Drizzles = setDrizzle.Quantity; newDrizzle.OrderItemId = orderItem.OrderItemId; newDrizzle.Price = (setDrizzle.Price * setDrizzle.Quantity); drizzleList.Add(null); drizzleList[i] = new Drizzle(); drizzleList[i].DrizzleType = newDrizzle.DrizzleType; drizzleList[i].Drizzles = newDrizzle.Drizzles; drizzleList[i].OrderItemId = newDrizzle.OrderItemId; drizzleList[i].Price = newDrizzle.Price; db.SaveChanges(); } orderItem.Drizzles = drizzleList; db.SaveChanges(); return(RedirectToAction("ReviewOrder", new { id = orderItem.OrderItemId })); }
public ActionResult EditShots(ICollection <MenuItem> shots) { Models.Customer customer = GetLoggedInCustomer(); Models.OrderItem orderItem = GetOrderItem(customer.CurrentOrderItemId); List <Shot> shotList = new List <Shot>(); for (int i = 0; i < shots.Count(); i++) { MenuItem setShot = shots.ElementAt(i); if (setShot.Quantity == null) { setShot.Quantity = 0; } Shot newShot = new Shot(); newShot.ShotType = setShot.Name; newShot.Shots = setShot.Quantity; newShot.OrderItemId = orderItem.OrderItemId; newShot.Price = (setShot.Price * setShot.Quantity); shotList.Add(null); shotList[i] = new Shot(); shotList[i].ShotType = newShot.ShotType; shotList[i].Shots = newShot.Shots; shotList[i].OrderItemId = newShot.OrderItemId; shotList[i].Price = newShot.Price; db.SaveChanges(); } orderItem.Shots = shotList; db.SaveChanges(); return(RedirectToAction("ReviewOrder", new { id = orderItem.OrderItemId })); }
public ActionResult EditOrderItem(int id, Models.OrderItem orderItem) { try { Models.Customer customer = GetLoggedInCustomer(); Models.OrderItem newOrderItem = db.OrderItems.FirstOrDefault(o => o.OrderItemId == customer.CurrentOrderItemId); newOrderItem.Size = orderItem.Size; newOrderItem.Room = orderItem.Room; newOrderItem.Decaf = orderItem.Decaf; newOrderItem.Temperature = orderItem.Temperature; newOrderItem.WhippedCream = orderItem.WhippedCream; Models.Order currentOrder = GetCurrentOrder(customer.CurrentOrderId); currentOrder.Status = 2; db.SaveChanges(); return(RedirectToAction("ReviewOrder", new { id = newOrderItem.OrderItemId })); } catch { return(View()); } }
public void MapOrderItemModelToEntity(Models.OrderItem orderItemMod, Entities.OrderItem orderItemEnt) { var mapper = new MapperConfiguration(configure => configure.CreateMap <Models.OrderItem, Entities.OrderItem>()) .CreateMapper(); mapper.Map(orderItemMod, orderItemEnt); }
public static OrderItem ToDomainModel(this Models.OrderItem orderItem) { return(new OrderItem(orderItem.Id) { ProductId = orderItem.ProductId, Quantity = orderItem.Quantity, UnitPrice = orderItem.UnitPrice }); }
public static DTO.Order_Item ToDTO(this Models.OrderItem oi) { DTO.Product product = new DTO.Product(); return(new DTO.Order_Item { id = oi.Id, product = oi.ProductId, quantity = oi.Quantity, }); }
public static void FillDto(Models.OrderItem entity, ViewModels.OrderItemDto orderitem) { orderitem.Id = entity.Id; orderitem.OrderId = entity.OrderId; orderitem.ProductId = entity.ProductId; orderitem.Quantity = entity.Quantity; orderitem.PriceUnit = entity.PriceUnit; orderitem.DiscountUnit = entity.DiscountUnit; orderitem.Remark = entity.Remark; orderitem.StatusId = entity.StatusId; }
public static DTO.OrderItem ToDTO(this Models.OrderItem op) { return(new DTO.OrderItem { OrderID = op.OrderID, ProductID = op.ProductId, Quantity = op.Quantity, Orders = op.Order?.ToDTO(), Products = op.Product?.toDTO() }); }
public Models.Order Create(Models.Cart cart) { Models.OrderItem orderItem = null; Models.Order newOrder = null; var orderItemLists = new List <Models.OrderItem>(); //if delivery type Id=1 then add 50 to total price if (cart.DeliveryId == 1) { cart.Totalprice = cart.Totalprice + 50; } try { using (var transaction = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled)) { newOrder = new Models.Order() { UserId = cart.UserId, OrderDate = DateTime.Now, PaymentId = cart.PaymentId, DeliveryId = cart.DeliveryId, Deliverd = false, TotalPrice = cart.Totalprice, Address = cart.Address }; _context.Orders.Add(newOrder); _context.SaveChanges(); foreach (var item in cart.CartItems) { orderItem = new Models.OrderItem() { OrderId = newOrder.Id, ProductId = item.Product.Id, Quantity = item.Quantity }; orderItemLists.Add(orderItem); } _context.OrderItems.AddRange(orderItemLists); _context.SaveChanges(); transaction.Complete(); } } catch (Exception e) { return(null); } return(newOrder); }
public static OrderItem ToOrderItemViewModel(this Models.OrderItem orderItem) { return(new OrderItem { Quantity = orderItem.Quantity, Id = orderItem.Id, GrossPrice = orderItem.GrossPrice, NetPrice = orderItem.NetPrice, TaxRate = orderItem.TaxRate, Name = orderItem.Name }); }
public static Models.OrderItemViewModel ToViewModel(this Models.OrderItem model) { return(new Models.OrderItemViewModel { Discount = model.Discount, ImagePath = model.ImagePath, Name = model.ImagePath, OrderId = model.OrderId, OrderItemId = model.Id, ProductId = model.ProductId, Qty = model.Qty, Sequence = model.Sequence, UnitePrice = model.UnitePrice }); }
public IActionResult Checkout(Orders order) { string userId = HttpContext.Session.GetString("UserId"); int userID = Convert.ToInt32(protector.Unprotect(userId.ToString())); if (cart.Lines.Count() == 0) { ModelState.AddModelError("", "Sorry, your cart is empty!"); } if (ModelState.IsValid) { order.Lines = cart.Lines.ToArray(); order.UserId = userID; var cost = order.Lines.Sum(e => e.Product.ProductPrice * e.Quantity).ToString("c"); ViewBag.Message = cost; order.TotalCost = order.Lines.Sum(e => e.Product.ProductPrice * e.Quantity); ViewBag.OrderId = order.OrderId; _context.Update(order); _context.SaveChanges(); foreach (var line in order.Lines) { Models.OrderItem item = new Models.OrderItem() { OrderId = order.OrderId, ProductId = line.Product.ProductID, StoreId = line.Product.StoreId, Quantity = line.Quantity, Cost = line.Product.ProductPrice * line.Quantity }; _context.OrderItems.Add(item); _context.SaveChanges(); } return(View("Payment", order)); } else { return(View(order)); } }
void ImportOrderItems(Models.Order order, IEnumerable <OrderItem> orderItems) { foreach (var orderItemData in orderItems) { var item = _context.Items.Single(i => i.LinkName == orderItemData.Item); var orderItem = _context.OrderItems.SingleOrDefault(oi => oi.ItemId == item.Id); if (orderItem == null) { orderItem = new Models.OrderItem(); orderItem.ItemId = item.Id; orderItem.OrderId = order.Id; } orderItem.Count = orderItemData.Quantity; orderItem.Price = orderItemData.Price; _context.SaveChanges(); } }
public IActionResult CrustSelected(Models.OrderItem selection) { var dbCrust = client.GetAllCrusts().FirstOrDefault(s => s.CrustType == selection.CrustType); if (dbCrust is null) { return(BadRequest("Somehow you got a null crust?")); } var sessionOrder = Utils.GetCurrentOrder(HttpContext.Session); var addedPizza = sessionOrder.Pizzas.Last(); addedPizza.Crust = dbCrust; Utils.SaveOrder(HttpContext.Session, sessionOrder); return(RedirectToAction("Menu", "Pizza")); }
public IActionResult ToppingSelected(Models.OrderItem ai) { var dbTopping = client.GetAllToppings().FirstOrDefault(s => s.ToppingType == ai.ToppingType); if (dbTopping is null) { return(BadRequest("Somehow you got a null topping?")); } var sessionOrder = Utils.GetCurrentOrder(HttpContext.Session); var addedPizza = sessionOrder.Pizzas.Last(); addedPizza.Toppings.Add(dbTopping); Utils.SaveOrder(HttpContext.Session, sessionOrder); return(RedirectToAction("Menu", "Pizza")); }
public async Task Create(OrderItemCreateModel orderItem) { if (orderItem.OrderId == null || await _orderAppService.GetById(orderItem.OrderId) == null) { throw new Exception("Order not found"); } if (orderItem.ProductId == null) { throw new Exception("No product given"); } var product = await _productAppService.GetById(orderItem.ProductId); if (product == null) { throw new Exception("No product match has been found."); } int newProductStock = product.Stock - orderItem.Quantity; product.Stock = newProductStock; await _productAppService.UpdateStock(product.Stock, product.Id); Models.OrderItem newOrderItem = new Models.OrderItem() { Number = product.Number, Price = product.Price, ProductId = product.Id, Description = product.Description, Name = product.Name, OrderId = orderItem.OrderId, Quantity = orderItem.Quantity, SKUCode = product.SKUCode, Tax = product.TaxGroup.Percentage, Weight = product.Weight }; await _repository.InsertAsync(newOrderItem); return; }
public async Task <ActionResult> AddItem(ViewModels.AddItem data) { var order = await db.Orders.Include("Items").Include("Items.Item").Where(x => x.Id == data.IdOrder).OrderByDescending(x => x.Created).FirstOrDefaultAsync(); if (order != null) { var item = await db.Items.FindAsync(data.Id); var exist = order.Items.Where(x => x.Item.Id == data.Id).FirstOrDefault(); if (exist != null) { exist.Amount = data.Amount; db.Entry(exist).State = EntityState.Modified; var result = await db.SaveChangesAsync(); if (result > 0) { return(RedirectToAction("PreviewOrder", new { id = data.IdOrder })); } } else { var addItem = new Models.OrderItem() { Id = Guid.NewGuid().ToString(), Amount = data.Amount, Item = item, Unit = item.Unit }; order.Items.Add(addItem); var result = await db.SaveChangesAsync(); if (result > 0) { return(RedirectToAction("PreviewOrder", new { id = data.IdOrder })); } } } return(View("Error")); }
// Gets the id of the drink from the view public ActionResult EditOrderItem(int id) { Models.Customer customer = GetLoggedInCustomer(); Models.OrderItem orderItem = new Models.OrderItem(); MenuItem menuItem = db.MenuItems.FirstOrDefault(m => m.MenuItemId == id); orderItem.OrderId = customer.CurrentOrderId; orderItem.ItemName = menuItem.Name; orderItem.Price = menuItem.Price; orderItem.IdFromMenu = id; orderItem.Duration = menuItem.Duration; db.OrderItems.Add(orderItem); db.SaveChanges(); customer.CurrentOrderItemId = orderItem.OrderItemId; db.SaveChanges(); ViewBag.temperatures = new SelectList(db.Temperatures.Where(s => s.MenuItemId == id && s.TemperatureName != null).ToList(), "TemperatureName", "TemperatureName"); ViewBag.sizes = new SelectList(db.Sizes.Where(s => s.MenuItemId == id && s.SizeName != null).ToList(), "SizeName", "SizeName"); return(View(orderItem)); }
private void Detail_BeforePrint(object sender, System.Drawing.Printing.PrintEventArgs e) { XRControl control = (XRControl)sender; int orderItemID = (int)this.GetCurrentColumnValue("[ID]"); Models.OrderItem oItem = new Models.OrderItem(); oItem = dbContext.OrderItems.FirstOrDefault(o => o.ID == orderItemID); int partID = oItem.PartID; Models.Part prt = new Models.Part(); prt = dbContext.Parts.FirstOrDefault(p => p.ID == partID); if (prt.Files.Count > 0) { int fileID = prt.Files.FirstOrDefault().FileId; Models.File fileItem = new Models.File(); fileItem = dbContext.Files.FirstOrDefault(f => f.FileId == fileID); if (fileItem.Content != null) { PdfViewer pdfViewer = new PdfViewer(); Stream stream = new MemoryStream(fileItem.Content); pdfViewer.LoadDocument(stream); Bitmap bitmap = pdfViewer.CreateBitmap(1, 950); bitmap.RotateFlip(RotateFlipType.Rotate90FlipNone); pdfViewer.CloseDocument(); pdfViewer.Dispose(); xrPictureBox1.ImageSource = new DevExpress.XtraPrinting.Drawing.ImageSource(bitmap); //string name = (string) this.GetCurrentColumnValue("FileName"); //xrLabel1.Text = name; } } }