public IHttpActionResult DeleteProductInOrder(int ID) { try { ProductsInOrder DeleteProduct = Core.db.ProductsInOrder.Find(ID); if (DeleteProduct == null) { ModelState.AddModelError("Errors", "Продукта в заказе с таким ID не существует"); } if (!ModelState.IsValid) { return(BadRequest(ModelState)); } Orders EditOrder = Core.db.Orders.Find(DeleteProduct.OrderID); EditOrder.Amount -= DeleteProduct.Amoount; EditOrder.Datetime = DateTime.Now; Core.db.ProductsInOrder.Remove(DeleteProduct); Core.db.SaveChanges(); return(Ok(DeleteProduct)); } catch (Exception ex) { ModelState.AddModelError("Errors", ex.InnerException); ModelState.AddModelError("Errors", ex.InnerException.InnerException); return(BadRequest(ModelState)); } }
public async Task <IActionResult> EditConnection(ProductsInOrder connection) { _context.ProductsInOrders.Update(connection); await _context.SaveChangesAsync(); return(RedirectToAction("ProductsInOrders")); }
public async Task <IActionResult> PutProductsInOrder(int id, ProductsInOrder productsInOrder) { if (id != productsInOrder.Id) { return(BadRequest()); } _context.Entry(productsInOrder).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ProductsInOrderExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <IActionResult> Edit(int id, [Bind("Id,orderId,productID")] ProductsInOrder productsInOrder) { if (id != productsInOrder.Id) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(productsInOrder); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ProductsInOrderExists(productsInOrder.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } ViewData["orderId"] = new SelectList(_context.Orders, "Id", "Id", productsInOrder.orderId); ViewData["productID"] = new SelectList(_context.Products, "Id", "Id", productsInOrder.productID); return(View(productsInOrder)); }
public ActionResult DeleteConfirmed(int id) { ProductsInOrder productsInOrder = db.ProductsInOrders.Find(id); db.ProductsInOrders.Remove(productsInOrder); db.SaveChanges(); return(RedirectToAction("Index", "Orders")); }
/// <summary> /// Осуществление преобравзования продукта из заказа в приемлимый вид /// </summary> /// <param name="product">Запись в таблице Products</param> public ProductsInOrderModel(ProductsInOrder product) { ID = product.ID; Product = new ProductsModel(product.Products); Status = product.Status.Name; Quantity = product.Quantity; Discount = product.Discount; Amount = product.Amoount; }
public IHttpActionResult EditProductInOrder(EditProductInOrderModel EditProduct) { try { ProductsInOrder SearchProdInOrd = Core.db.ProductsInOrder.Find(EditProduct.EditID); Products SearchProd = Core.db.Products.Find(EditProduct.ProductID); Orders SearchOrd = Core.db.Orders.Find(Core.db.ProductsInOrder.Find(EditProduct.EditID).OrderID); if (SearchProdInOrd == null) { ModelState.AddModelError("Errors", "Продукт в заказе не найден"); } if (SearchProd == null) { ModelState.AddModelError("Errors", "Продукт не найден"); } if (SearchOrd == null) { ModelState.AddModelError("Errors", "Заказ не найден"); } if (Core.db.Status.Find(EditProduct.StatusID) == null) { ModelState.AddModelError("Errors", "Такого статуса не существует"); } if (EditProduct.Quantity <= 0) { ModelState.AddModelError("Errors", "Количество продукта в заказе должно быть больше нуля"); } if (!ModelState.IsValid) { return(BadRequest(ModelState)); } SearchProdInOrd.ProductID = EditProduct.ProductID; SearchProdInOrd.Quantity = EditProduct.Quantity; SearchProdInOrd.StatusID = EditProduct.StatusID; SearchProdInOrd.Discount = EditProduct.Discount; SearchProdInOrd.Amoount = (SearchProd.Price - SearchProd.Price * (EditProduct.Discount / 100)) * EditProduct.Quantity; SearchOrd.Amount = 0; foreach (var item in SearchOrd.ProductsInOrder) { SearchOrd.Amount += item.Amoount; } Core.db.SaveChanges(); return(Ok(new ProductsInOrderModel(SearchProdInOrd))); } catch (Exception ex) { ModelState.AddModelError("Errors", ex.InnerException); ModelState.AddModelError("Errors", ex.InnerException.InnerException); return(BadRequest(ModelState)); } }
public async Task <IActionResult> AddProductsInOrder(ProductsInOrder productsInOrder) { // Указываем номер уже существующего документа // Указываем номер уже существующего продукта // Указываем количество данного продукта в документе _context.ProductsInOrders.Add(productsInOrder); await _context.SaveChangesAsync(); return(RedirectToAction("ProductsInOrders")); }
public IHttpActionResult CreateProductInNewOrder(CreateProductInNewOrderModel NewOrder) { try { if (Core.db.Users.Find(NewOrder.UserID) == null) { ModelState.AddModelError("Errors", "Пользователя с таким ID не существует"); } if (Core.db.Status.Find(NewOrder.StatusID) == null) { ModelState.AddModelError("Errors", "Такого статуса не существует "); } if (NewOrder.Quantity <= 0) { ModelState.AddModelError("Errors", "Количество продукта в заказе должно быть больше нуля"); } Products SelectProduct = Core.db.Products.Find(NewOrder.ProductID); if (SelectProduct == null) { ModelState.AddModelError("Errors", "Такого продукта не существует"); } if (!ModelState.IsValid) { return(BadRequest(ModelState)); } Orders CreateOrder = new Orders(); CreateOrder.UserID = NewOrder.UserID; CreateOrder.Amount = SelectProduct.Price * (NewOrder.Discount / 100); CreateOrder.Datetime = DateTime.Now; Core.db.Orders.Add(CreateOrder); Core.db.SaveChanges(); ProductsInOrder CreateProdInOrder = new ProductsInOrder(); CreateProdInOrder.OrderID = CreateOrder.ID; CreateProdInOrder.ProductID = NewOrder.ProductID; CreateProdInOrder.Quantity = NewOrder.Quantity; CreateProdInOrder.StatusID = NewOrder.StatusID; CreateProdInOrder.Amoount = (SelectProduct.Price - SelectProduct.Price * (NewOrder.Discount / 100)) * NewOrder.Quantity; CreateProdInOrder.Discount = NewOrder.Discount; Core.db.ProductsInOrder.Add(CreateProdInOrder); Core.db.SaveChanges(); return(Ok(new ProductsInOrderModel(CreateProdInOrder))); } catch (Exception ex) { ModelState.AddModelError("Errors", ex.InnerException); ModelState.AddModelError("Errors", ex.InnerException.InnerException); return(BadRequest(ModelState)); } }
private void AddProductToOrder() { if (selectedProduct != null) { var productOrder = new ProductOrder() { Product = selectedProduct, Quantity = quantity, }; ProductsInOrder.Add(productOrder); } }
public ActionResult Remove(int id) { ProductsInOrder productsInOrder = this.db.ProductsInOrders.Find(id); this.service.RemoveProduct(productsInOrder); new ProductService().AddProduct(productsInOrder.Product, 1); this.db.SaveChanges(); return(RedirectToAction("Index", "Orders")); }
public async Task <IActionResult> Create([Bind("Id,orderId,productID")] ProductsInOrder productsInOrder) { if (ModelState.IsValid) { _context.Add(productsInOrder); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["orderId"] = new SelectList(_context.Orders, "Id", "Id", productsInOrder.orderId); ViewData["productID"] = new SelectList(_context.Products, "Id", "Id", productsInOrder.productID); return(View(productsInOrder)); }
public async Task <IActionResult> ConfirmDeleteConnection(int?id) { if (id != null) { ProductsInOrder connection = await _context.ProductsInOrders.FirstOrDefaultAsync(p => p.Id == id); if (connection != null) { return(View(connection)); } } return(NotFound()); }
// GET: ProductsInOrders/Delete/5 public ActionResult Delete(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } ProductsInOrder productsInOrder = db.ProductsInOrders.Find(id); if (productsInOrder == null) { return(HttpNotFound()); } return(View(productsInOrder)); }
public ActionResult Edit([Bind(Include = "Id,Count,Cost,Active,ProductId,OrderId,Added,Updated,AdderId,ModifierId")] ProductsInOrder productsInOrder) { if (ModelState.IsValid) { db.Entry(productsInOrder).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.AdderId = new SelectList(db.Profiles, "Id", "UserName", productsInOrder.AdderId); ViewBag.ModifierId = new SelectList(db.Profiles, "Id", "UserName", productsInOrder.ModifierId); ViewBag.OrderId = new SelectList(db.Orders, "Id", "Id", productsInOrder.OrderId); ViewBag.ProductId = new SelectList(db.Products, "Id", "Name", productsInOrder.ProductId); return(View(productsInOrder)); }
public async Task <IActionResult> DeleteConnection(int?id) { if (id != null) { ProductsInOrder connection = await _context.ProductsInOrders.FirstOrDefaultAsync(p => p.Id == id); if (connection != null) { _context.ProductsInOrders.Remove(connection); await _context.SaveChangesAsync(); return(RedirectToAction("ProductsInOrders")); } } return(NotFound()); }
public ProductInOrder ProductInOrder(ProductsInOrder productsInOrder) { return(new ProductInOrder() { Id = productsInOrder.Id, Name = productsInOrder.Product.Name, Cost = productsInOrder.Cost, Count = productsInOrder.Count, Active = productsInOrder.Active, Order = productsInOrder.Order, Creator = productsInOrder.Adder.UserName, Modifier = productsInOrder.Modifier.UserName, Created = productsInOrder.Added, Updated = productsInOrder.Updated }); }
// GET: ProductsInOrders/Edit/5 public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } ProductsInOrder productsInOrder = db.ProductsInOrders.Find(id); if (productsInOrder == null) { return(HttpNotFound()); } ViewBag.AdderId = new SelectList(db.Profiles, "Id", "UserName", productsInOrder.AdderId); ViewBag.ModifierId = new SelectList(db.Profiles, "Id", "UserName", productsInOrder.ModifierId); ViewBag.OrderId = new SelectList(db.Orders, "Id", "Id", productsInOrder.OrderId); ViewBag.ProductId = new SelectList(db.Products, "Id", "Name", productsInOrder.ProductId); return(View(productsInOrder)); }
public IHttpActionResult DetailsProductsInOrders(int ID) { try { ProductsInOrder Search = Core.db.ProductsInOrder.Find(ID); if (Search == null) { ModelState.AddModelError("Error", "Такой записи не существует"); return(BadRequest(ModelState)); } return(Ok(new ProductsInOrderModel(Search))); } catch (Exception ex) { ModelState.AddModelError("Errors", ex.InnerException); ModelState.AddModelError("Errors", ex.InnerException.InnerException); return(BadRequest(ModelState)); } }
public Object Details(int orderid) { List <ProductsInOrder> products = new List <ProductsInOrder>(); OrderWithAllDetails order = null; { try { using (var db = new PCPartsDB()) { //Information about Order var auxOrder = db.Orders.Find(orderid); //Info ab var productOrder = db.Product_Order.Where(po => po.OrderFK == auxOrder.OrderID).ToList(); foreach (var item in productOrder) { var product = db.Products.Where(p => p.ProductID == item.ProductFK).FirstOrDefault(); string supplier = db.Suppliers.Where(s => s.SupplierID == product.SupplierFK).Select(s => s.Name).FirstOrDefault(); ProductsInOrder prd = new ProductsInOrder { Product = product, Quantity = item.Quantity, SupplierName = supplier }; products.Add(prd); } order = new OrderWithAllDetails(products, auxOrder); } } catch (Exception) { return(null); } if (order == null) { return(new { result = false, info = "Erro ao retornar os detalhes da order." }); } return(new { result = true, data = order }); } }
public ActionResult AddProduct(int id) { Profile profile = db.Profiles.Single(a => a.UserName == User.Identity.Name); Order order = this.db.Orders.Order( profile, this.service ); Product p = this.db.Products.Find(id); if (order.Id.Equals(0)) { return(RedirectToAction("Index")); } ProductsInOrder productsInOrder = new ProductsInOrder() { OrderId = order.Id, ProductId = p.Id, Added = DateTime.Now, Updated = DateTime.Now, AdderId = profile.Id, ModifierId = profile.Id, Active = true, Cost = p.Cost, Count = 1 }; new ProductService().RemoveProduct(p, 1); this.db.ProductsInOrders.Add(productsInOrder); this.db.SaveChanges(); return(RedirectToAction("Index", "Products")); }
private async void CreateOrderExecute() { Order newOrder = new Order(); string shipCountry = "USA"; newOrder.CustomerID = SelectedCustomer.CustomerID; newOrder.EmployeeID = SelectedEmployee.EmployeeID; newOrder.OrderDate = DateTime.Parse(OrderDate); newOrder.ShipCountry = shipCountry; ProductsInOrder.ForEach(productInOrder => productInOrder.IsSaled = true); var orderDetails = ProductsInOrder.Select(p => new Order_Detail { ProductID = p.ProductID, UnitPrice = (decimal)p.UnitPrice, Quantity = (short)p.SelectedQuantity, Discount = p.SelectedDiscount / 100 }).ToList(); await northwindRepository.AddOrder(newOrder, orderDetails); int id = (await northwindRepository.GetOrders()).Last().OrderID; RemoveAllCommand.Execute().Subscribe(); productsInOrder.Clear(); OrderDate = String.Empty; SelectedCustomer = null; SelectedEmployee = null; MessageBus.Current.SendMessage <NewOrderCreated>(new NewOrderCreated() { OrderId = id }); }
public ProductsInOrder RemoveProduct(ProductsInOrder productsInOrder) { productsInOrder.Active = false; return(productsInOrder); }