Beispiel #1
0
        public ActionResult Index()
        {
            List <ProductOrder> productOrders = new List <ProductOrder>();

            try
            {
                string  username  = Session["username"].ToString();
                Account a         = new AccountServ.AccountServiceClient().getAccountByUsername(username);
                int     accountID = a.ID;

                List <Order> ordersList = new ProductOrderServ.ProductOrderClient().getPurchasesUnderWarranty(accountID).ToList();
                foreach (Order i in ordersList)
                {
                    List <ProductOrder> po = new ProductOrderServ.ProductOrderClient().getProductOrderByOrderID(i.ID).ToList();

                    foreach (ProductOrder p in po)
                    {
                        productOrders.Add(p);
                    }
                }
                return(View("Index", productOrders));
            }
            catch (Exception ex)
            {
                TempData["CatchError"] = "An error was encountered. Please try again later";
                return(View("Index", productOrders));
            }
        }
Beispiel #2
0
        public ActionResult UserHistory()
        {
            try
            {
                string  username  = Session["username"].ToString();
                Account a         = new AccountServ.AccountServiceClient().getAccountByUsername(username);
                int     accountID = a.ID;

                List <Order> ordersList = new ProductOrderServ.ProductOrderClient().getShippedOrders(accountID).ToList();



                foreach (Order i in ordersList)
                {
                    List <ProductOrder> po = new ProductOrderServ.ProductOrderClient().getProductOrderByOrderID(i.ID).ToList();

                    foreach (ProductOrder p in po)
                    {
                        productOrders.Add(p);
                    }
                }

                ProductModel pm = new ProductModel();
                pm.productOrderList = productOrders;
                return(View("UserHistory", pm));
            }
            catch (Exception ex)
            {
                TempData["CatchError"] = "An error was encountered. Please try again later";
                return(View("UserHistory", productOrders));
            }
        }
Beispiel #3
0
        public ActionResult Checkout()
        {
            string  username  = Session["username"].ToString();
            Account a         = new AccountServ.AccountServiceClient().getAccountByUsername(username);
            int     accountID = a.ID;

            Order o       = new ProductOrderServ.ProductOrderClient().getUserProductOrder(accountID, "Ordered");
            int   orderID = o.ID;

            Order order = new Order();

            order.ID                 = o.ID;
            order.DateOfPurchase     = o.DateOfPurchase;
            order.WarrantyExpiryDate = o.WarrantyExpiryDate;
            order.Status             = "Shipped";
            order.AccountID          = o.AccountID;

            foreach (ProductOrder p in o.ProductOrder)
            {
                ProductServ.ProductServiceClient productClient = new ProductServ.ProductServiceClient();
                Product product = productClient.GetProductByID(p.ProductID);
                product.StockAmount = product.StockAmount - p.Quantity;
                productClient.UpdateProductStock(product.StockAmount.Value, product.ID);
            }
            //Product p = new ProductServ.ProductServiceClient().GetProductByID(o.ProductOrder.
            new ProductOrderServ.ProductOrderClient().UpdateOrder(order);
            return(RedirectToAction("ProductList", "Product"));
        }
Beispiel #4
0
        public ActionResult Details(int pid, int oid)
        {
            ProductOrder po = new ProductOrderServ.ProductOrderClient().getProductOrderID(pid, oid);

            //Product p = new ProductServ.ProductServiceClient().GetProductByID(id);
            //to show fault


            return(View("Details", po));
        }
Beispiel #5
0
        public ActionResult Delete(int productID)
        {
            string  username  = Session["username"].ToString();
            Account a         = new AccountServ.AccountServiceClient().getAccountByUsername(username);
            int     accountID = a.ID;

            Order o       = new ProductOrderServ.ProductOrderClient().getUserProductOrder(accountID, "Ordered");
            int   orderID = o.ID;

            new ProductOrderServ.ProductOrderClient().DeleteProductOrderByIDs(productID, orderID);
            return(RedirectToAction("Index"));
        }
Beispiel #6
0
        public ActionResult ShowReport(int productID, int orderID, string dateF, string dateT)
        {
            ReportModel model = new ReportModel();

            ViewBag.Title = "Electros";
            string  username  = Session["username"].ToString();
            Account a         = new AccountServ.AccountServiceClient().getAccountByUsername(username);
            int     accountID = a.ID;

            Order o = new ProductOrderServ.ProductOrderClient().getOrderByIDs(accountID, orderID);

            Product            p  = new ProductServ.ProductServiceClient().GetProductByID(productID);
            List <FaultReport> fr = new FaultsServ.FaultReportLogServiceClient().getFaultByAccountIDPRoductID(accountID, productID).ToList();

            model.myFaultReport = fr;
            List <FaultLog> faultLogList = new List <FaultLog>();

            foreach (FaultReport f in fr)
            {
                List <FaultLog> flTemp = new FaultsServ.FaultReportLogServiceClient().getFaultLogByReportID(f.ID).ToList();
                foreach (FaultLog fl in flTemp)
                {
                    //faultLogList.Add(fl);
                    model.myFaultLog = flTemp;
                }
            }

            if (model.myFaultLog == null)
            {
                TempData["NoFault"] = "The item selected has no faults";
                return(RedirectToAction("UserHistory"));
            }
            model.myProduct = p;
            //model.myFaultReport = fr;
            //model.myFaultLog = faultLogList;
            model.myOrder = o;
            //model.from = Convert.ToDateTime(TempData["StoreDataFrom"]) ;
            //model.to = Convert.ToDateTime(TempData["StoreDataTo"]);
            model.from = Convert.ToDateTime(dateF);
            model.to   = Convert.ToDateTime(dateT);

            sendEmailToClient(accountID, model);

            return(new RazorPDF.PdfResult(model, "ShowReport"));
            //return View(model);
        }
Beispiel #7
0
        //
        // GET: /Basket/

        public ActionResult Index()
        {
            string  username = Session["username"].ToString();
            Account a        = new AccountServ.AccountServiceClient().getAccountByUsername(username);

            if (a != null)
            {
                int accountID = a.ID;

                Order o = new ProductOrderServ.ProductOrderClient().getUserProductOrder(accountID, "Ordered");
                if (o != null)
                {
                    int orderID = o.ID;

                    List <ProductOrder> productOrders = new ProductOrderServ.ProductOrderClient().getProductOrderByOrderID(orderID).ToList();

                    //to show totalPrice
                    decimal price;
                    int     qty;
                    decimal totalPrice = 0;
                    foreach (ProductOrder i in productOrders)
                    {
                        Product product = new ProductServ.ProductServiceClient().GetProductByID(i.ProductID);

                        price       = Convert.ToDecimal(i.Product.Price);
                        qty         = Convert.ToInt32(i.Quantity);
                        totalPrice += price * qty;
                    }
                    ViewData["totalPrice"] = totalPrice;
                    return(View("Index", productOrders));
                }
                else
                {
                    return(View("Index", new List <ProductOrder>()));
                }
            }
            else
            {
                return(RedirectToAction("Login", "UserAuthentication"));
            }
        }
Beispiel #8
0
        public ActionResult AddToCart(ProductModel p)
        {
            try
            {
                if (p.Qty <= 0 || p.Qty.Equals(""))
                {
                    TempData["ErrorMsg"] = "Quantity cannot be less than zero or empty";
                    Product      pro       = new ProductServ.ProductServiceClient().GetProductByID(p.myProduct.ID);
                    double       avgRating = new ProductServ.ProductServiceClient().getAverageRating(p.myProduct.ID);
                    ProductModel pm        = new ProductModel();
                    pm.myProduct     = pro;
                    pm.averageRating = avgRating;
                    return(View("Details", pm));
                }
                Product product   = new ProductServ.ProductServiceClient().GetProductByID(p.myProduct.ID);
                int     stock     = Convert.ToInt32(product.StockAmount);
                string  username  = Session["username"].ToString();
                Account a         = new AccountServ.AccountServiceClient().getAccountByUsername(username);
                int     accountID = a.ID;

                Order check = new ProductOrderClient().getOrderIDByAccountIDStatus(accountID, "Ordered");
                if (p.Qty <= stock)
                {
                    if (check == null)
                    {
                        Order newOrder = new Order();
                        //newOrder.ID = new int();
                        newOrder.DateOfPurchase     = System.DateTime.Today;
                        newOrder.WarrantyExpiryDate = System.DateTime.Today.AddYears(2);
                        newOrder.Status             = "Ordered";
                        newOrder.AccountID          = accountID;
                        new ProductOrderServ.ProductOrderClient().addOrder(newOrder);

                        Order details = new ProductOrderServ.ProductOrderClient().getOrderIDByAccountIDStatus(accountID, newOrder.Status);

                        ProductOrder newProductOrder = new ProductOrder();
                        newProductOrder.OrderID   = details.ID;
                        newProductOrder.ProductID = p.myProduct.ID;
                        newProductOrder.Quantity  = p.Qty;

                        new ProductOrderServ.ProductOrderClient().addProductOrder(newProductOrder);
                        //return RedirectToAction("Details");
                    }
                    else if (check != null)
                    {
                        ProductOrder checkpo = new ProductOrderServ.ProductOrderClient().getProductOrderID(p.myProduct.ID, check.ID);

                        if (checkpo == null)
                        {
                            Order details = new ProductOrderServ.ProductOrderClient().getOrderIDByAccountIDStatus(accountID, "Ordered");

                            ProductOrder newProductOrder = new ProductOrder();
                            newProductOrder.OrderID   = details.ID;
                            newProductOrder.ProductID = p.myProduct.ID;
                            newProductOrder.Quantity  = p.Qty;

                            new ProductOrderServ.ProductOrderClient().addProductOrder(newProductOrder);
                        }
                        else if (checkpo != null)
                        {
                            ProductOrder newProductOrder = checkpo;
                            //newProductOrder.Quantity = checkpo.Quantity + p.Qty;
                            int newQty = Convert.ToInt32(checkpo.Quantity) + p.Qty;

                            // new ProductOrderServ.ProductOrderClient().UpdateProductOrder(newProductOrder);
                            new ProductOrderServ.ProductOrderClient().UpdateQtyProduct(newQty, checkpo.ProductID, checkpo.OrderID);
                        }
                    }
                }
                else if (p.Qty > stock)
                {
                    @TempData["OutOfStock"] = "The selected Item is out of stock, try again later";
                    //return RedirectToAction("ProductList");
                    Product      pro       = new ProductServ.ProductServiceClient().GetProductByID(p.myProduct.ID);
                    double       avgRating = new ProductServ.ProductServiceClient().getAverageRating(p.myProduct.ID);
                    ProductModel m         = new ProductModel();
                    m.myProduct     = pro;
                    m.averageRating = avgRating;
                    return(View("Details", m));
                }
                return(RedirectToAction("ProductList"));
            }
            catch (Exception ex)
            {
                TempData["Error"] = "An error has occurred. Please try again later";
                Product      pro       = new ProductServ.ProductServiceClient().GetProductByID(p.myProduct.ID);
                double       avgRating = new ProductServ.ProductServiceClient().getAverageRating(p.myProduct.ID);
                ProductModel m         = new ProductModel();
                m.myProduct     = pro;
                m.averageRating = avgRating;
                return(View("Details", m));
            }
        }
Beispiel #9
0
        public ActionResult Filter(string dateFrom, string dateTo)
        {
            DateTime parsed;

            try
            {
                if (dateFrom.Equals("") && dateTo.Equals(""))
                {
                    TempData["NullMsg"] = "Dates cannot be null";
                    return(RedirectToAction("UserHistory"));
                }
                //if (!Decimal.TryParse(lowPrice, out parsed) && !Decimal.TryParse(highPrice, out parsed)  )
                if (!DateTime.TryParse(dateFrom, out parsed) && !DateTime.TryParse(dateTo, out parsed))
                {
                    TempData["DatesError"] = "The Dates are incorrect format or null (2014/12/12)";
                    return(RedirectToAction("UserHistory"));
                }
                else
                {
                    from = Convert.ToDateTime(dateFrom);
                    to   = Convert.ToDateTime(dateTo);
                    //try
                    //{
                    //    from = Convert.ToDateTime(dateFrom);
                    //    to = Convert.ToDateTime(dateTo);
                    //}
                    //catch (Exception e)
                    //{
                    //    string user = Session["username"].ToString();
                    //    Account aa = new AccountServ.AccountServiceClient().getAccountByUsername(user);
                    //    int accID = aa.ID;

                    //    List<Order> oList = new ProductOrderServ.ProductOrderClient().getShippedOrders(accID).ToList();
                    //    foreach (Order i in oList)
                    //    {
                    //        List<ProductOrder> po = new ProductOrderServ.ProductOrderClient().getProductOrderByOrderID(i.ID).ToList();

                    //        foreach (ProductOrder p in po)
                    //        {
                    //            productOrders.Add(p);
                    //        }
                    //    }
                    //    //change
                    //    ProductModel pm1 = new ProductModel();
                    //    pm1.productOrderList = productOrders;
                    //    pm1.from = Convert.ToDateTime(dateFrom);
                    //    pm1.to = Convert.ToDateTime(dateTo);
                    //    TempData["DatesError"] = "The Dates are incorrect format or null (2014/12/12)";
                    //   // return View("UserHistory", productOrders);
                    //    return View("UserHistory",pm1);
                    //}
                    TempData["StoreDataFrom"] = from;
                    TempData["StoreDataTo"]   = to;
                    string  username  = Session["username"].ToString();
                    Account a         = new AccountServ.AccountServiceClient().getAccountByUsername(username);
                    int     accountID = a.ID;

                    List <Order> ordersList = new ProductServ.ProductServiceClient().getPurchasesByDates(accountID, from, to).ToList();
                    //new ProductOrderServ.ProductOrderClient().getShippedOrders(accountID).ToList();
                    // List<Order>


                    foreach (Order i in ordersList)
                    {
                        List <ProductOrder> po = new ProductOrderServ.ProductOrderClient().getProductOrderByOrderID(i.ID).ToList();

                        foreach (ProductOrder p in po)
                        {
                            productOrders.Add(p);
                        }
                    }

                    ProductModel pm = new ProductModel();
                    pm.productOrderList = productOrders;
                    pm.from             = Convert.ToDateTime(dateFrom);
                    pm.to = Convert.ToDateTime(dateTo);
                    //pm.myProduct

                    return(View("UserHistory", pm));
                }
            }
            catch (Exception ex)
            {
                //ProductModel pm = new ProductModel();
                //pm.productOrderList = productOrders;
                //pm.from = Convert.ToDateTime(dateFrom);
                //pm.to = Convert.ToDateTime(dateTo);
                TempData["CatchError"] = "An error was encountered. Please try again later";
                return(View("UserHistory", productOrders));
                // return View("UserHistory",pm);
            }
        }