public ActionResult Basket() { BasketModel model = new BasketModel(); if (CurrentUser != null) { AccountOrder order = CurrentUser.AccountOrders.LastOrDefault(ord => !ord.Completed); if (order != null) { model.SumPrice = order.Sum; model.OrderId = order.Id; foreach (AccountOrderRecord record in order.AccountOrderRecords) { if (record.ProductType == typeof(Book).Name) { model.BookProducts.Add( new BookModel( DataContext.Books.FirstOrDefault(book => book.Id == record.ProductId))); } if (record.ProductType == typeof(Journal).Name) { model.JournalProducts.Add( new JournalModel( DataContext.Journals.FirstOrDefault( journal => journal.Id == record.ProductId))); } if (record.ProductType == typeof(Newspaper).Name) { model.NewspaperProducts.Add( new NewspaperModel( DataContext.Newspapers.FirstOrDefault( newspaper => newspaper.Id == record.ProductId))); } } } } if (CurrentVisitor != null) { VisitorOrder order = CurrentVisitor.VisitorOrders.LastOrDefault(ord => !ord.Completed); if (order != null) { model.SumPrice = order.Sum; model.OrderId = order.Id; foreach (VisitorOrderRecord record in order.VisitorOrderRecords) { if (record.ProductType == typeof(Book).Name) { model.BookProducts.Add( new BookModel( DataContext.Books.FirstOrDefault(book => book.Id == record.ProductId))); } if (record.ProductType == typeof(Journal).Name) { model.JournalProducts.Add( new JournalModel( DataContext.Journals.FirstOrDefault( journal => journal.Id == record.ProductId))); } if (record.ProductType == typeof(Newspaper).Name) { model.NewspaperProducts.Add( new NewspaperModel( DataContext.Newspapers.FirstOrDefault( newspaper => newspaper.Id == record.ProductId))); } } } } model.BreadcrumbModel = new BreadcrumbModel(Url.Action("Basket", "Sell", null, Request.Url.Scheme)); model.CurrentUser = CurrentUser; model.CurrentNavSection = NavSection.Basket; return(View("Basket", model)); }
public IHttpActionResult Basket() { BasketModel model = new BasketModel(); if (CurrentUser != null) { try { AccountOrder order = CurrentUser.AccountOrders.LastOrDefault(ord => !ord.Completed); if (order != null) { model.SumPrice = order.Sum; model.OrderId = order.Id; foreach (AccountOrderRecord record in order.AccountOrderRecords) { if (record.ProductType == typeof(Book).Name) { model.BookProducts.Add( new BookModel( DataContext.Books.FirstOrDefault(book => book.Id == record.ProductId))); } if (record.ProductType == typeof(Journal).Name) { model.JournalProducts.Add( new JournalModel( DataContext.Journals.FirstOrDefault( journal => journal.Id == record.ProductId))); } if (record.ProductType == typeof(Newspaper).Name) { model.NewspaperProducts.Add( new NewspaperModel( DataContext.Newspapers.FirstOrDefault( newspaper => newspaper.Id == record.ProductId))); } } } } catch (Exception e) { return(InternalServerError(e)); } } if (CurrentVisitor != null) { try { VisitorOrder order = CurrentVisitor.VisitorOrders.LastOrDefault(ord => !ord.Completed); if (order != null) { model.SumPrice = order.Sum; model.OrderId = order.Id; foreach (VisitorOrderRecord record in order.VisitorOrderRecords) { if (record.ProductType == typeof(Book).Name) { model.BookProducts.Add( new BookModel( DataContext.Books.FirstOrDefault(book => book.Id == record.ProductId))); } if (record.ProductType == typeof(Journal).Name) { model.JournalProducts.Add( new JournalModel( DataContext.Journals.FirstOrDefault( journal => journal.Id == record.ProductId))); } if (record.ProductType == typeof(Newspaper).Name) { model.NewspaperProducts.Add( new NewspaperModel( DataContext.Newspapers.FirstOrDefault( newspaper => newspaper.Id == record.ProductId))); } } } } catch (Exception e) { return(InternalServerError(e)); } } return(Ok(model)); }
public ActionResult AcceptSellOrder(int orderId) { if (CurrentUser != null) { AccountOrder order = DataContext.AccountOrders.FirstOrDefault(ord => ord.Id == orderId); if (order != null) { foreach (AccountOrderRecord record in order.AccountOrderRecords) { if (record.ProductType == typeof(Book).Name) { DataContext.Books.FirstOrDefault(book => book.Id == record.ProductId).Amount -= record.Count; } if (record.ProductType == typeof(Journal).Name) { DataContext.Journals.FirstOrDefault(jor => jor.Id == record.ProductId).Amount -= record.Count; } if (record.ProductType == typeof(Newspaper).Name) { DataContext.Newspapers.FirstOrDefault(np => np.Id == record.ProductId).Amount -= record.Count; } } order.Completed = true; DataContext.SubmitChanges(); } } if (CurrentVisitor != null) { VisitorOrder order = DataContext.VisitorOrders.FirstOrDefault(ord => ord.Id == orderId); if (order != null) { foreach (VisitorOrderRecord record in order.VisitorOrderRecords) { if (record.ProductType == typeof(Book).Name) { DataContext.Books.FirstOrDefault(book => book.Id == record.ProductId).Amount -= record.Count; } if (record.ProductType == typeof(Journal).Name) { DataContext.Journals.FirstOrDefault(jor => jor.Id == record.ProductId).Amount -= record.Count; } if (record.ProductType == typeof(Newspaper).Name) { DataContext.Newspapers.FirstOrDefault(np => np.Id == record.ProductId).Amount -= record.Count; } } order.Completed = true; DataContext.SubmitChanges(); } } return(RedirectToAction("Basket")); }
public IHttpActionResult AcceptSellOrder(AcceptSellOrderModel orderId) { if (CurrentUser != null) { try { AccountOrder order = DataContext.AccountOrders.FirstOrDefault(ord => ord.Id == orderId.OrderId); if (order != null) { foreach (AccountOrderRecord record in order.AccountOrderRecords) { if (record.ProductType == typeof(Book).Name) { DataContext.Books.FirstOrDefault(book => book.Id == record.ProductId).Amount -= record.Count; } if (record.ProductType == typeof(Journal).Name) { DataContext.Journals.FirstOrDefault(jor => jor.Id == record.ProductId).Amount -= record.Count; } if (record.ProductType == typeof(Newspaper).Name) { DataContext.Newspapers.FirstOrDefault(np => np.Id == record.ProductId).Amount -= record.Count; } } order.Completed = true; DataContext.SubmitChanges(); } } catch (Exception e) { return(InternalServerError(e)); } } if (CurrentVisitor != null) { try { VisitorOrder order = DataContext.VisitorOrders.FirstOrDefault(ord => ord.Id == orderId.OrderId); if (order != null) { foreach (VisitorOrderRecord record in order.VisitorOrderRecords) { if (record.ProductType == typeof(Book).Name) { DataContext.Books.FirstOrDefault(book => book.Id == record.ProductId).Amount -= record.Count; } if (record.ProductType == typeof(Journal).Name) { DataContext.Journals.FirstOrDefault(jor => jor.Id == record.ProductId).Amount -= record.Count; } if (record.ProductType == typeof(Newspaper).Name) { DataContext.Newspapers.FirstOrDefault(np => np.Id == record.ProductId).Amount -= record.Count; } } order.Completed = true; DataContext.SubmitChanges(); } } catch (Exception e) { return(InternalServerError(e)); } } return(Ok()); }