예제 #1
0
        public void DeleteCurrentOrder(FinalOrder order)
        {
            using (var context = new eBikesContext())
            {
                var updatedOrder = context.PurchaseOrders.Find(order.PurchaseOrderID);
                var details      = context.PurchaseOrderDetails.Where(x => x.PurchaseOrderID == updatedOrder.PurchaseOrderID)?.ToList();

                if (updatedOrder == null)
                {
                    throw new Exception("Order does not exist.");
                }
                if (updatedOrder.OrderDate != null)
                {
                    throw new Exception("Order has already been placed. ");
                }
                else
                {
                    //going through the original list of details and comparing it with the new one
                    foreach (var item in details)
                    {
                        context.PurchaseOrderDetails.Remove(item);
                    }

                    context.PurchaseOrders.Remove(updatedOrder);
                    context.SaveChanges();
                }
            }
        }
예제 #2
0
        public void MiddleOrder(MiddleOrder model, string username)
        {
            ApplicationDbContext context    = new ApplicationDbContext();
            FinalOrder           finalOrder = new FinalOrder();

            finalOrder.Date = DateTime.Now;
            List <ApplicationUser> listuser  = context.Users.ToList();
            List <FinalOrder>      listfo    = context.FinalOrders.ToList();
            FinalOrder             lastfinal = listfo.Last();
            ApplicationUser        user      = listuser.Find(m => m.Email.Equals(username));

            finalOrder.ApplicationUserId = user.Id;
            finalOrder.FinalAmount       = 0;
            finalOrder.IsConfirmed       = false;
            finalOrder.FinalOrderId      = lastfinal.FinalOrderId + 1;

            context.FinalOrders.Add(finalOrder);

            MiddleOrder middleOrder = new MiddleOrder();

            middleOrder.FinalOrderId = finalOrder.FinalOrderId;
            middleOrder.CookiesId    = model.CookiesId;
            middleOrder.Number       = model.Number;
            middleOrder.MiddleAmount = 0;

            context.MiddleOrders.Add(middleOrder);
            context.SaveChanges();
        }
        public ActionResult ConfirmOrder(FinalOrder order)
        {
            int          total = 0;
            ShoppingCart cart  = (ShoppingCart)Session[WebUtil.CART];

            if (cart != null && cart.NumberOfItems > 0)
            {
                foreach (var c in cart.Items)
                {
                    ShoppingCartItem cartItem = new ShoppingCartItem
                    {
                        Id       = c.Id,
                        Name     = c.Name,
                        Price    = c.Price,
                        Quantity = c.Quantity,
                        ImageURL = c.ImageURL,
                        Sale     = c.Sale
                    };
                    order.ShoppingCartItem.Add(cartItem);
                    total += c.Amount;
                }
                ViewBag.total = total;
            }
            return(View(order));
        }
예제 #4
0
        public void Invoice()
        {
            ProcessOrder po = new ProcessOrder()
            {
                ProductImage  = "https://www.google.co.in/search?q=product+images&tbm=isch&source=iu&ictx=1&fir=Ys6s1aKrzB6hrM%253A%252ChoD76SE7hB_ZTM%252C_&usg=AI4_-kRULqtxH-vZZChrfKQOclXWU2y_hw&sa=X&ved=2ahUKEwjIsurpndjeAhVKQY8KHVJ6CvkQ9QEwAnoECAAQCA#imgrc=Ys6s1aKrzB6hrM:",
                Title         = "EarPhones",
                Price         = 1200,
                Quantity      = 5,
                ReorderLevel  = 10,
                Description   = "Nice EarPhones",
                CategoryId    = 62,
                SubCategoryId = 64,
                ProductId     = 129,
                sum           = 6000
            };
            List <ProcessOrder> lst = new List <ProcessOrder>();

            lst.Add(po);

            FinalOrder finalOrder = new FinalOrder()
            {
                products = lst, CustomerId = 100, PaymentMode = "COD"
            };
            var            result  = bookingController.Invoice(finalOrder) as OkObjectResult;
            InvoiceDetails details = (InvoiceDetails)result.Value;

            InvoiceNo = details.InvoiceNo;
            Assert.IsInstanceOfType(result.Value, typeof(InvoiceDetails));
        }
예제 #5
0
        public ActionResult DeleteConfirmed(int id)
        {
            FinalOrder finalOrder = db.FinalOrders.Find(id);

            db.FinalOrders.Remove(finalOrder);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
        public ActionResult Checkout(FinalOrder order)
        {
            if (ModelState.IsValid)
            {
                return(RedirectToAction("ConfirmOrder", order));
            }

            return(View());
        }
예제 #7
0
 public ActionResult Edit([Bind(Include = "FinalOrderId,FinalAmount,Date,IsConfirmed")] FinalOrder finalOrder)
 {
     if (ModelState.IsValid)
     {
         db.Entry(finalOrder).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(finalOrder));
 }
예제 #8
0
        public ActionResult Create([Bind(Include = "FinalOrderId,FinalAmount,Date,IsConfirmed")] FinalOrder finalOrder)
        {
            if (ModelState.IsValid)
            {
                db.FinalOrders.Add(finalOrder);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(finalOrder));
        }
 public CartViewModel(IEventAggregator eventAggregator)
 {
     myOrder        = new OrderDetails();
     _selectedOrder = new FinalOrder();
     _myCart        = new ObservableCollection <FinalOrder>();
     eventAggregator.GetEvent <UpdateEvent>().Subscribe(getOrder);
     client.BaseAddress = new Uri("http://localhost:58076/");
     client.DefaultRequestHeaders.Clear();
     client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
     deleteCommand     = new DelegateCommand(deleteOrder);
     placeOrderCommand = new DelegateCommand(placeOrder);
 }
예제 #10
0
        public int AddOrder(FinalOrder order)
        {
            int sum = 0, Quantity = 0;

            OrderDetails[] ary = new OrderDetails[order.products.Length];
            foreach (var i in order.products)
            {
                sum      += (int)i.Price * i.Quantity;
                Quantity += i.Quantity;
            }
            Orders o = new Orders()
            {
                OrderDate     = DateTime.Now,
                OrderAmount   = sum,
                OrderQuantity = Quantity,
                CustomerId    = order.CustomerId,
            };


            context.Orders.Add(o);
            context.SaveChanges();
            for (int j = 0; j < order.products.Length; j++)
            {
                ary[j] = new OrderDetails()
                {
                    OrderId    = o.OrderId,
                    BookId     = order.products[j].BookId,
                    Quantity   = order.products[j].Quantity,
                    OrderPrice = order.products[j].Price
                };
            }
            context.OrderDetails.AddRange(ary);
            context.SaveChanges();

            Payment p = new Payment()
            {
                PaymentMethod = order.PaymentMethod,
                OrderId       = o.OrderId
            };

            context.Payment.Add(p);
            context.SaveChanges();
            Book temp;

            foreach (var i in order.products)
            {
                temp = context.Book.SingleOrDefault(c => c.BookId == i.BookId);
                temp.BookQuantity -= i.Quantity;
            }
            context.SaveChanges();
            return(p.InvoiceNumber);
        }
예제 #11
0
        public ActionResult Delete(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            FinalOrder finalOrder = db.FinalOrders.Find(id);

            if (finalOrder == null)
            {
                return(HttpNotFound());
            }
            return(View(finalOrder));
        }
예제 #12
0
        public IActionResult SaveOrders([FromBody] FinalOrder finalOrder)
        {
            Order order = new Order();

            order.OrderItems = finalOrder.SelectedOrderItem;
            order.TotalPrice = finalOrder.TotalPrice;
            var d = DateTime.Now.ToString("yyyy-MM-dd");

            order.Date = DateTime.Parse(d);

            context.Orders.Add(order);
            var result = context.SaveChanges();

            return(Accepted(result));
        }
예제 #13
0
        public InvoiceDetails Invoice(FinalOrder finalOrder)
        {
            int    sum    = 0;
            Orders orders = new Orders();

            orders.CustomerId   = finalOrder.CustomerId;
            orders.OrderDate    = DateTime.Now;
            orders.DeliveryDate = DateTime.Now.AddDays(7);


            for (int i = 0; i < finalOrder.products.Count; i++)
            {
                sum += finalOrder.products[i].Quantity * finalOrder.products[i].Price;
            }
            orders.TotalAmount = sum;
            context.Orders.Add(orders);
            context.SaveChanges();
            //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
            ProductOrderDetails[] products = new ProductOrderDetails[finalOrder.products.Count];
            for (int i = 0; i < finalOrder.products.Count; i++)
            {
                products[i] = new ProductOrderDetails()
                {
                    OrderId   = orders.OrderId,
                    ProductId = finalOrder.products[i].ProductId,
                    Price     = finalOrder.products[i].Price,
                    Quantity  = finalOrder.products[i].Quantity
                };
            }
            context.ProductOrderDetails.AddRange(products);

            Payment payment = new Payment();

            payment.Method      = finalOrder.PaymentMode;
            payment.OrderId     = orders.OrderId;
            payment.PaymentDate = DateTime.Now;

            context.Payment.Add(payment);
            context.SaveChanges();
            Customer customer = context.Customer.SingleOrDefault(c => c.CustomerId == finalOrder.CustomerId);

            customer.Orders = null;
            InvoiceDetails details = new InvoiceDetails();

            details.customer  = customer;
            details.InvoiceNo = payment.InvoiceNo;
            return(details);
        }
예제 #14
0
        public IActionResult Payment(string optradio)
        {
            InvoiceDetails data;

            if (optradio != null)
            {
                ApparelStoreApplication.Models.BookingService svc = new ApparelStoreApplication.Models.BookingService();
                svc.context = HttpContext;
                FinalOrder details = svc.PlaceOrder(optradio, out data);

                ViewData["details"] = details;
                ViewData["invoice"] = data;
                return(View("Invoice"));
            }
            return(View());
        }
예제 #15
0
        protected void Delete_Click(object sender, EventArgs e)
        {
            MessageUserControl.TryRun(() =>
            {
                var poid = Convert.ToInt32((CurrentOrderGridView.Rows[0].FindControl("PurchaseOrderID") as HiddenField).Value);
                if (poid == 0)
                {
                    throw new Exception("empty");
                }
                FinalOrder purchase              = new FinalOrder();
                purchase.PurchaseOrderID         = Convert.ToInt32((CurrentOrderGridView.Rows[0].FindControl("PurchaseOrderID") as HiddenField).Value);
                purchase.VendorID                = int.Parse(VendorDropDown.SelectedValue);
                purchase.Subtotal                = decimal.Parse(Subtotal.Text.Substring(1));
                purchase.GST                     = decimal.Parse(GST.Text.Substring(1));
                List <CurrentOrder> orderDetails = new List <CurrentOrder>();

                foreach (GridViewRow row in CurrentOrderGridView.Rows)
                {
                    var partid = row.FindControl("PartID") as Label;
                    var qty    = row.FindControl("Qty") as TextBox;
                    var price  = row.FindControl("Price") as TextBox;

                    if (partid != null)
                    {
                        var details    = new CurrentOrder();
                        details.PartID = int.Parse(partid.Text);
                        details.Qty    = int.Parse(qty.Text);
                        details.Price  = decimal.Parse(price.Text);
                        orderDetails.Add(details);
                    }
                    else
                    {
                        throw new Exception("Empty");
                    }
                }

                var controller = new PurchasingController();
                controller.DeleteCurrentOrder(purchase);
                OrderDetailsPanel.Enabled    = false;
                OrderDetailsPanel.Visible    = false;
                VendorDropDown.SelectedIndex = 0;
                VendorName.Text = "";
                Location.Text   = "";
                Phone.Text      = "";
            }, "Success", "Order deleted");
        }
예제 #16
0
        protected void Update_Click(object sender, EventArgs e)
        {
            MessageUserControl.TryRun(() =>
            {
                CalculateTotals();

                FinalOrder purchase            = new FinalOrder();
                purchase.PurchaseOrderID       = Convert.ToInt32((CurrentOrderGridView.Rows[0].FindControl("PurchaseOrderID") as HiddenField).Value);
                purchase.PurchaseOrderDetailID = Convert.ToInt32((CurrentOrderGridView.Rows[0].FindControl("PurchaseOrderDetailID") as HiddenField).Value);
                purchase.VendorID = int.Parse(VendorDropDown.SelectedValue);
                purchase.Subtotal = decimal.Parse(Subtotal.Text.Substring(1));
                purchase.GST      = decimal.Parse(GST.Text.Substring(1));
                List <CurrentOrder> orderDetails = new List <CurrentOrder>();

                foreach (GridViewRow row in CurrentOrderGridView.Rows)
                {
                    var partid = row.FindControl("PartID") as Label;
                    var qty    = row.FindControl("Qty") as TextBox;
                    var price  = row.FindControl("Price") as TextBox;
                    if (int.Parse(qty.Text) < 0)
                    {
                        throw new Exception("Quantity cannot be a negative number");
                    }
                    if (decimal.Parse(price.Text) <= 0)
                    {
                        throw new Exception("Price cannot be a negative number");
                    }
                    if (partid != null)
                    {
                        var details    = new CurrentOrder();
                        details.PartID = int.Parse(partid.Text);
                        details.Qty    = int.Parse(qty.Text);
                        details.Price  = decimal.Parse(price.Text);
                        orderDetails.Add(details);
                    }
                    else
                    {
                        throw new Exception("Empty");
                    }
                }

                var controller        = new PurchasingController();
                purchase.OrderDetails = orderDetails;
                controller.UpdateCurrentOrder(purchase);
            }, "Sucess", "Order updated.");
        }
        public ActionResult Checkout()
        {
            User currentUser = (User)Session[WebUtil.CURRENT_USER];

            //User currentUser = new UserHandler().GetUser(user.Id);

            FinalOrder fo = new FinalOrder();

            if (currentUser != null)
            {
                fo.Email       = currentUser.Email;
                fo.FullAddress = currentUser.FullAddress;
                fo.Name        = currentUser.FullName;
                fo.Phone       = currentUser.Phone;

                return(RedirectToAction("ConfirmOrder", fo));
            }
            return(View());
        }
예제 #18
0
        public ActionResult FinalOrder()
        {
            ApplicationDbContext      context     = new ApplicationDbContext();
            List <ApplicationUser>    listuser    = context.Users.ToList();
            ApplicationUser           user        = listuser.Find(m => m.Email.Equals(User.Identity.Name));
            List <FinalOrder>         listfo      = context.FinalOrders.ToList();
            List <Cookies>            listcookies = context.Cookies.ToList();
            IEnumerable <MiddleOrder> listmi      = context.MiddleOrders.ToList();

            foreach (MiddleOrder middle in listmi)
            {
                middle.Cookies = listcookies.Last(m => m.CookiesId.Equals(middle.CookiesId));
            }
            FinalOrder final = listfo.Last(m => m.ApplicationUserId.Equals(user.Id));
            IEnumerable <MiddleOrder> listmiddle = listmi.Where(m => m.FinalOrderId.Equals(final.FinalOrderId));

            ViewBag.ListMiddle = listmiddle;
            ViewBag.FinalOrder = final;

            return(View());
        }
예제 #19
0
        public void Orders()
        {
            FinalOrder obj = new FinalOrder()
            {
                PaymentMethod = "COD",
                products      = new ProductViewModelCart[]
                {
                    new ProductViewModelCart()
                    {
                        BookId   = 204,
                        Price    = 400,
                        Quantity = 8,
                        Title    = "Final Test",
                    }
                },
                CustomerId = 111
            };
            var result = controller2.AddOrder(obj) as OkObjectResult;

            InvoiceNo = (int)result.Value;
            Assert.IsInstanceOfType(result, typeof(OkObjectResult));
        }
예제 #20
0
        public async Task <int> SaveDetails(ProductViewModelCart[] p, string PayMode)
        {
            string     InvoiceId;
            string     Cid   = context.Session.GetString("Customer");
            FinalOrder order = new FinalOrder();

            order.CustomerId    = Convert.ToInt32(Cid);
            order.PaymentMethod = PayMode;
            order.products      = p;
            string              json    = JsonConvert.SerializeObject(order);
            HttpContent         content = new StringContent(json, Encoding.UTF8, "application/json");
            HttpResponseMessage message = await client.PostAsync("OrderService/AddOrder", content);

            if (message.IsSuccessStatusCode == true)
            {
                InvoiceId = await message.Content.ReadAsStringAsync();

                return(Convert.ToInt32(InvoiceId));
            }
            else
            {
                return(0);
            }
        }
예제 #21
0
        public IActionResult Invoice(FinalOrder finalOrder)
        {
            InvoiceDetails invoicedetails = service.Invoice(finalOrder);

            return(Ok(invoicedetails));
        }
예제 #22
0
        public void PlaceOrder(FinalOrder order)
        {
            using (var context = new eBikesContext())
            {
                var updatedOrder = context.PurchaseOrders.Find(order.PurchaseOrderID);
                var details      = context.PurchaseOrderDetails.Where(x => x.PurchaseOrderID == updatedOrder.PurchaseOrderID)?.ToList();

                if (order.OrderDetails.Count == 0)
                {
                    throw new Exception("An empty order cannot be placed. Please, add items to the order.");
                }
                else
                {
                    updatedOrder.OrderDate           = DateTime.Today;
                    updatedOrder.PurchaseOrderNumber = context.PurchaseOrders.Max(x => x.PurchaseOrderNumber) + 1;
                    updatedOrder.SubTotal            = order.Subtotal;
                    updatedOrder.TaxAmount           = order.GST;

                    //going through the original list of details and comparing it with the new one
                    foreach (var item in details)
                    {
                        var changedpart = order.OrderDetails.SingleOrDefault(x => x.PartID == item.PartID);

                        //if part is not there anymore, then delete it
                        if (changedpart == null)
                        {
                            context.Entry(item).State = EntityState.Deleted;
                        }
                        else
                        {
                            item.Quantity             = changedpart.Qty;
                            item.PurchasePrice        = changedpart.Price;
                            context.Entry(item).State = EntityState.Modified;
                        }
                    }

                    foreach (var item in order.OrderDetails)
                    {
                        var newpart = !details.Any(x => x.PartID == item.PartID);
                        if (newpart == true)
                        {
                            //check if they added a zero
                            if (item.Qty == 0)
                            {
                                throw new Exception("You cannot add a product into an order with 0 as quantity");
                            }
                            else
                            {
                                var newitem = new PurchaseOrderDetail
                                {
                                    PartID        = item.PartID,
                                    Quantity      = item.Qty,
                                    PurchasePrice = item.Price
                                };
                                updatedOrder.PurchaseOrderDetails.Add(newitem);
                            }

                            //update Quantity on Order after order is placed
                            var updatedPart = context.Parts.Find(item.PartID);
                            updatedPart.QuantityOnOrder = item.Qty;
                        }
                    }
                    context.Entry(updatedOrder).State = EntityState.Modified;
                    context.SaveChanges();
                }
            }
        }
        public IActionResult AddOrder(FinalOrder order)
        {
            int result = service.AddOrder(order);

            return(Ok(result));
        }
        public ActionResult PlaceOrder(FinalOrder order)
        {
            ShoppingCart cart = (ShoppingCart)Session[WebUtil.CART];

            if (cart != null && cart.NumberOfItems > 0)
            {
                foreach (var c in cart.Items)
                {
                    ShoppingCartItem cartItem = new ShoppingCartItem
                    {
                        Id       = c.Id,
                        Name     = c.Name,
                        Price    = c.Price,
                        Quantity = c.Quantity,
                        ImageURL = c.ImageURL,
                        Sale     = c.Sale
                    };
                    order.ShoppingCartItem.Add(cartItem);
                }

                order.OrderStatus = "Pending";
                dynamic randomNumber = Path.GetRandomFileName().Replace(".", "");
                order.OrderNumber = randomNumber;
            }
            new OrderHandler().AddOrder(order);
            Session.Clear();

            // Sending Product Email

            try
            {
                var message = new MailMessage();
                message.To.Add(new MailAddress(order.Email));
                message.Subject = "-No-Reply- Shopping Details";

                // BODY Making Here to Send HTML page in email.

                message.IsBodyHtml = true;

                string       body   = string.Empty;
                StreamReader reader = new StreamReader(Server.MapPath("~/Views/Cart/orderemail.html"));
                using (reader)
                {
                    body = reader.ReadToEnd();
                }

                body = body.Replace("{track}", order.OrderNumber);
                body = body.Replace("{username}", order.Name);

                //message.Body = "Please use this password: "******" , Next Time You Login! And dont forget to change your password";
                message.Body = body;

                using (var smtp = new SmtpClient())
                {
                    smtp.Send(message);
                    ViewBag.success = "Email Has been sent to  " + order.Email;
                }
                return(View(order));
            }
            catch (Exception)
            {
                ViewBag.error = "Error Sending Mail. Please Try Again Later!";
            }
            return(View(order));
        }
 private void getOrder(FinalOrder fo)
 {
     _myCart.Add(fo);
     finalCost += fo.TotalCost;
     MessageBox.Show(fo.productName + " with quantity = " + fo.Quantity + " has been added to the cart");
 }