public static void ProcessOrder(OrderDTO newOrder) { decimal total = CalculateTotal(newOrder); newOrder.Total = total; OrdersRepository.AddOrder(newOrder); }
public ActionResult Create(OrdersViewModel viewModel) { try { if (ModelState.IsValid) { var customer = _customerRepo.GetById(viewModel.CustomerId); var location = _locationRepo.GetById(viewModel.LocationId); var order = new Orders { OrderId = viewModel.OrderId, Date = viewModel.Date }; var theNewOrder = _ordersRepo.AddOrder(order, customer, location); //store the location ID that user inputed TempData["userLocation"] = location.LocationId; _ordersRepo.Insert(theNewOrder); _ordersRepo.SaveToDB(); return(RedirectToAction(nameof(CustomerController.DetailsOfNewOrder), "Customer", new { id = viewModel.CustomerId })); } return(View(viewModel)); } catch (ArgumentException) { ModelState.AddModelError("", "Invalid, please try again"); return(View(viewModel)); } }
public ActionResult AddOrder(CreateOrderRequest createRequest) { if (!_validator.Validate(createRequest)) { return(BadRequest(new { error = "Please fill the whole form" })); } var newOrder = _ordersRepository.AddOrder(createRequest); return(Created($"api/orders/{newOrder.Id}", newOrder)); }
public void AddOrder(Order order) { var ordersRepository = new OrdersRepository(); var productsRepository = new ProductsRepository(); var customersRepository = new CustomersRepository(); order.Customer = customersRepository.GetById(order.CustomerId); order.OrderItems.ToList().ForEach(x => x.Product = productsRepository.GetById(x.ProductId)); ordersRepository.AddOrder(order); }
public ActionResult AddOrder(int custId) { Order o = new Order { CustomerID = custId, OrderDate = DateTime.Now, TotalQuantity = 0, TotalCost = 0, TotalAmountPaid = 0 }; var repo = new OrdersRepository(); repo.AddOrder(o); return(Redirect("/Orders/OrderDetails?orderId=" + o.OrderID)); }
// POST: api/OrdersPox public void Post([RawRequestDataAttribute] string xml) { using (StringReader textReader = new StringReader(xml)) { XmlReaderSettings settings = new XmlReaderSettings(); // .NET 4.5.2 and after => Default is Prohibit. Setting to Parse makes vulnerable // Before .NET 4.5.2 this was set to Parse by default (which was vulnerable) settings.DtdProcessing = DtdProcessing.Parse; XmlReader reader = XmlReader.Create(textReader, settings); XmlSerializer serializer = new XmlSerializer(typeof(OrderModel)); var orderModel = serializer.Deserialize(reader) as OrderModel; ordersRepository.AddOrder(orderModel); } }
//place order public ActionResult placeOrder(int cartId) { _orderRepo.AddOrder(cartId); return(View("thankyou")); }
public ActionResult Create(Order order) { ordersRepository.AddOrder(order); return(RedirectToAction("Index")); }
public void PlaceOrder(string username, Guid orderID, List <CartView> products) { OrdersRepository or = new OrdersRepository(); ProductsRepository pr = new ProductsRepository(); TradersMarketPlaceEntities tm = new TradersMarketPlaceEntities(); or.Entity = pr.Entity = tm; Order o = new Order(); o.OrderID = orderID; o.Username = username; o.OrderDate = DateTime.Now; o.OrderStatusID = 1; //Paid Status OrderDetail od; decimal totalPrice = 0M; try { or.Entity.Database.Connection.Open(); or.Transaction = pr.Transaction = or.Entity.Database.Connection.BeginTransaction(); or.AddOrder(o); foreach (CartView p in products) { od = new OrderDetail(); od.OrderID = orderID; od.ProductID = p.ProductID; od.ProductQty = p.ProductQuantity; totalPrice += (p.ProductPrice * p.ProductQuantity); or.AddOrderDetails(od); pr.DecreaseStock(p.ProductID, p.ProductQuantity); } foreach (Cart sc in pr.GetCartForUser(username)) { pr.RemoveShoppingCart(sc); } try { //Send an email to the administrator to notify them about the commission string adminEmail = new UsersRepository().GetAdminEmail(); decimal commission = 0.1M; MailMessage mm = new MailMessage(); mm.To.Add(adminEmail); mm.From = new MailAddress("*****@*****.**", "Trader's Marketplace"); mm.Subject = "Order Commission"; mm.Body = "Dear Admin, <br/><br/>An order with ID " + orderID + " has been placed.<br/>"; mm.Body += "You have received 10% of the order total as a commission: €" + Math.Round(commission * (totalPrice), 2); mm.Body += "<br/><br/>Regards, <br/>Traders MarketPlace"; mm.IsBodyHtml = true; SmtpClient client = new SmtpClient("smtp.gmail.com", 587); client.EnableSsl = true; client.DeliveryMethod = SmtpDeliveryMethod.Network; client.Credentials = new NetworkCredential("*****@*****.**", "fabfashadmin"); client.Send(mm); or.Transaction.Commit(); } catch (SmtpException e) { or.Transaction.Rollback(); } } catch (Exception ex) { or.Transaction.Rollback(); } finally { or.Entity.Database.Connection.Close(); } }
/// <summary> /// Adds an Order /// Level: Logic /// </summary> /// <param name="SupplierFK">Supplier ID</param> /// <param name="UserFK">User ID</param> /// <param name="myOrderItems">Collection of Order Items</param> /// <returns>True if successful false if not successful</returns> public bool AddOrder(int?SupplierFK, Guid?UserFK, string CreditCard, List <OrderItem> myOrderItems) { DbTransaction myTransaction = null; OrdersRepository myRepository = new OrdersRepository(); myRepository.Entities.Connection.Open(); using (myTransaction = myRepository.Entities.Connection.BeginTransaction()) { try { Order myOrder = new Order(); myOrder.Id = Guid.NewGuid(); myOrder.OrderDate = DateTime.Now; myOrder.OrderStatusFK = myRepository.RetrieveStatusByName("Ordered").Id; myOrder.UserFK = UserFK; myOrder.SupplierFK = SupplierFK; myRepository.AddOrder(myOrder); if (SupplierFK != null) { myRepository.AddOrderItems(myOrder.Id, myOrderItems); myTransaction.Commit(); myRepository.Entities.Connection.Close(); return(true); } else { if (myRepository.AddUserOrderItems(myOrder.Id, myOrderItems)) // if mismatch occurs for quantity rollback { myTransaction.Rollback(); myRepository.Entities.Connection.Close(); return(false); } else //else commit changes { myTransaction.Commit(); new UsersLogic().InsertCreditCardNumber(CreditCard, Guid.Parse(UserFK.ToString())); new ShoppingCartLogic().EmptyCart(Guid.Parse(UserFK.ToString())); User myUser = new UsersRepository().RetrieveUserById(Guid.Parse(UserFK.ToString())); new Mailing().PurchaseMail(myUser.UserDetail.Username, myUser.Email, myOrder.Id.ToString(), "*****@*****.**"); myRepository.Entities.Connection.Close(); return(true); } } } catch (Exception Exception) { if (myTransaction != null) { myTransaction.Rollback(); } if (myRepository != null) { myRepository.Entities.Connection.Close(); } throw Exception; } } }
public ActionResult PlaceOrder(IFormCollection viewCollection, ViewModel myModel, Users user) { //int userid = int.Parse(viewCollection["UseridTD"].ToString()); //TempData["result"] = userid; int UseridTD = int.Parse(TempData.Peek("userid").ToString()); int LocationTD = int.Parse(TempData.Peek("locationid").ToString()); string NameTD = TempData.Peek("firstname").ToString(); string LastnameTD = TempData.Peek("lastname").ToString(); string PhoneTD = TempData.Peek("phone").ToString(); PizzaModel newPizza = new PizzaModel(); OrderModel order = new OrderModel(); ViewData["msg"] = "Add a Pizza"; if (Count == 11) { ViewData["msg"] = "You can create only one more pizza, (max of 12 pizzas per order)"; } else if (Count == 12) { ViewData["msg"] = "You have reach your maximun of pizzas per order (12 pizzas), Please place your order "; return(RedirectToAction(nameof(PlaceOrder))); } //ViewModel myModel = new ViewModel(); newPizza.Crust = int.Parse(viewCollection["SelectedCrust"].ToString()); newPizza.Size = viewCollection["SelectedSize"]; newPizza.Name = viewCollection["SelectedPizza"]; string sauce = viewCollection["SelectedSauce"]; // order.LocationId = user.LocationId; order.LocationId = user.LocationId; order.OrderTotal = 0; order.UsersId = user.UsersId; var toppings = new List <string>(); toppings.Add(newPizza.Name); Pizzas pizza = new Pizzas { Crust = newPizza.Crust, Size = newPizza.Size, Name = newPizza.Name }; //calculate price decimal S = 6, M = 8, L = 12; //quantity of topppings batch for pizza size if (pizza.Size == "S") { pizza.Price = S; Order_total = int.Parse(TempData.Peek("order_total").ToString()); Order_total += S; TempData["order_total"] = Order_total; } else if (pizza.Size == "M") { pizza.Price = M; Order_total = int.Parse(TempData.Peek("order_total").ToString()); Order_total += M; TempData["order_total"] = Order_total; } else { pizza.Price = L; Order_total = int.Parse(TempData.Peek("order_total").ToString()); Order_total += L; TempData["order_total"] = Order_total; } //check availability of ingredients for each pizza bool availability = Repo.CheckInventory(toppings, pizza, sauce, LocationTD); if (availability == true) { // take out toppings from db Repo.MinusToppings(toppings, pizza, sauce, LocationTD); //add pizza Repo.AddPizzas(pizza.Size, pizza.Price, pizza.Name, pizza.Crust); Repo.SaveChanges(); if (TempData.Peek("Count").ToString() == "1") { Count = 1; } else { Count = int.Parse(TempData.Peek("Count").ToString()); } if (Count < 2)//only if the order is new is going to be created { //add order Repo.AddOrder(UseridTD, LocationTD, Order_total); } // increment counter to know next time, that this is not a new order. Count++; TempData["Count"] = Count; //add orderPizza int?order_id = Repo.GetOrderByUserId(UseridTD); int?pizza_id = Repo.GetPizzaIdBySize(pizza.Name, pizza.Size); TempData["orderid"] = order_id; Repo.AddOrderPizza(order_id, pizza_id); } else { ViewData["msg"] = "Not enough reseources to complete your order, Please choose again..."; return(RedirectToAction(nameof(PlaceOrder))); } return(RedirectToAction(nameof(PlaceOrder))); }
// POST: api/Orders public void Post([FromBody] OrderModel order) { ordersRepository.AddOrder(order); }