public async Task <RSOrderItem> AddOrderItem(int id, [FromBody] int productId) { RSOrder order = await db.Orders.FindAsync(id); if (!order.Active) //Disallow editing closed orders { return(null); } RSProduct product = await db.Products.FindAsync(productId); if (order != null && product != null) { RSOrderItem oi = new RSOrderItem(product, order); db.OrderItems.Add(oi); await db.SaveChangesAsync(); return(new RSOrderItem() { Id = oi.Id, Price = oi.Price, State = oi.State, Product = oi.Product != null ? new RSProduct() { Id = oi.Product.Id, Title = oi.Product.Title } : null }); } else { return(null); } }
public RSOrder GetOrder(int id) { RSOrder order = db.Orders.Include("Items.Product").SingleOrDefault(i => i.Id == id); if (order == null) { return(null); } return(new RSOrder() { Id = order.Id, Active = order.Active, CreatedOn = order.CreatedOn, Notes = order.Notes, Title = order.Title, Items = order.Items != null?order.Items.Select(oi => new RSOrderItem() { Id = oi.Id, Price = oi.Price, State = oi.State, Product = oi.Product != null ? new RSProduct() { Id = oi.Product.Id, Title = oi.Product.Title } : null }).ToList() : null }); }
public ActionResult DeleteConfirmed(int id) { RSOrder rsorder = db.Orders.Find(id); db.Orders.Remove(rsorder); db.SaveChanges(); return(RedirectToAction("Index")); }
public async Task <RSOrder> CreateOrder([FromBody] string title) { RSOrder order = new RSOrder(); order.Title = title; db.Orders.Add(order); await db.SaveChangesAsync(); return(order); }
private async void btnReload_Click(object sender, RoutedEventArgs e) { if (order != null) { order = await Service.GetOrder(order.Id); lstOrderItems.ItemsSource = order.Items.Where(oi => oi.State < 2); this.DataContext = order; } }
public ActionResult Edit([Bind(Include = "Id,Title,CreatedOn,Active,Notes")] RSOrder rsorder) { if (ModelState.IsValid) { db.Entry(rsorder).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(rsorder)); }
public ActionResult Create([Bind(Include = "Id,Title,CreatedOn,Active,Notes")] RSOrder rsorder) { if (ModelState.IsValid) { db.Orders.Add(rsorder); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(rsorder)); }
private void navigationHelper_LoadState(object sender, LoadStateEventArgs e) { if (e.NavigationParameter is RSOrder) { order = e.NavigationParameter as RSOrder; } if (order != null) { grdOrderItems.ItemsSource = order.Items.Where(oi => oi.State < 2); } }
// GET: /Orders/Delete/5 public ActionResult Delete(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } RSOrder rsorder = db.Orders.Find(id); if (rsorder == null) { return(HttpNotFound()); } return(View(rsorder)); }
private async void navigationHelper_LoadState(object sender, LoadStateEventArgs e) { if (e.NavigationParameter is int) { order = await Service.GetOrder((int)e.NavigationParameter); } if (e.NavigationParameter is RSOrder) { order = await Service.GetOrder((e.NavigationParameter as RSOrder).Id); } lstOrderItems.ItemsSource = order.Items.Where(oi => oi.State < 2); this.DataContext = order; }
public async Task <ActionResult> Details(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } RSOrder rsorder = await db.Orders.Include(o => o.Items).SingleOrDefaultAsync(o => o.Id == id); if (rsorder == null) { return(HttpNotFound()); } return(View(rsorder)); }
private async void btnAddOrder_Click(object sender, RoutedEventArgs e) { btnNewOrder.Flyout.Hide(); RSOrder order = await Service.CreateOrder(txtNewOrderName.Text); if (order != null) { btnRefresh_Click(null, null); } else { MessageDialog md = new MessageDialog("Nebylo možno vytvořit objednávku.", "Vytvoření objednávky"); await md.ShowAsync(); } txtNewOrderName.Text = ""; }
public async Task <bool> CloseOrder(int id) { RSOrder order = await db.Orders.FindAsync(id); foreach (RSOrderItem item in order.Items) //All items must be resolved { if (item.State < (int)RSOrderItemState.Canceled) { return(false); } } order.Active = false; await db.SaveChangesAsync(); return(true); }
public async Task <ActionResult> RemoveProduct(int id, int productId) { RSOrderItem product = await db.OrderItems.FindAsync(productId); RSOrder order = await db.Orders.FindAsync(id); if (product != null && order != null) { if (order.Items.Remove(product)) { db.OrderItems.Remove(product); await db.SaveChangesAsync(); return(Json(true)); } } throw new HttpException(400, "Error removing item"); }
public async Task <ActionResult> AddProduct(int id, int productId) { RSProduct product = await db.Products.FindAsync(productId); RSOrder order = await db.Orders.FindAsync(id); if (product != null && order != null) { RSOrderItem orderItem = new RSOrderItem(product, order); db.OrderItems.Add(orderItem); await db.SaveChangesAsync(); return(Json(true)); } else { throw new HttpException(400, "Error inserting OrderItem"); } }
public int CreateReceipt(int id, [FromBody] IEnumerable <int> orderItemIds) { try { RSReceipt receipt = new RSReceipt(); RSOrder order = db.Orders.Find(id); receipt.Order = order; receipt.User = db.Users.Find((User.Identity as RSUser).Id); var orderItems = orderItemIds.Select(oiid => db.OrderItems.Include("Product.Stocks.Stock").SingleOrDefault(oi => oi.Id == oiid)); if (orderItems.All(oi => oi != null ? oi.State < 2 : false)) { foreach (var orderItem in orderItems) { orderItem.Receipt = receipt; //Product was used, modify stock quantity foreach (var stockItem in orderItem.Product.Stocks) { stockItem.Stock.Quantity -= stockItem.Amount; } orderItem.State = (int)RSOrderItemState.Paid; } } else { return(-1); } db.Receipts.Add(receipt); db.SaveChanges(); return(receipt.Id); } catch (Exception ex) { return(-1); } }
private async void btnCreateReceipt_Click(object sender, RoutedEventArgs e) { btnAcceptReceipt.IsEnabled = false; grdOrderItems.IsEnabled = false; if (grdOrderItems.SelectedItems.Count == 0) { MessageDialog md = new MessageDialog("Potvrzení účtenky nebylo možno provést. Musíte označit alespoň jednu položku.", "Potvrzení účtenky"); await md.ShowAsync(); btnAcceptReceipt.IsEnabled = true; grdOrderItems.IsEnabled = true; return; } int receiptId = await Service.CreateReceipt(order.Id, grdOrderItems.SelectedItems.OfType <RSOrderItem>().Select(oi => oi.Id).ToList()); if (receiptId >= 0) { string receiptHtml = await Service.GenerateReceipt(receiptId); webReceipt.NavigateToString(receiptHtml); await PrintManager.ShowPrintUIAsync(); } else { MessageDialog md = new MessageDialog("Potvrzení účtenky nebylo možno provést. Je možné že jde konflikt mezi zařízeními. Prosíme zkuste vytvořit účtenku znovu s aktuálními daty, které pro Vás aplikace načte.", "Potvrzení účtenky"); await md.ShowAsync(); order = await Service.GetOrder(order.Id); grdOrderItems.ItemsSource = order.Items.Where(oi => oi.State < 2); btnAcceptReceipt.IsEnabled = true; grdOrderItems.IsEnabled = true; } }