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")); }
public ActionResult PostComment(int proID) { Product p = new ProductServ.ProductServiceClient().GetProductByID(proID); CommentModel model = new CommentModel(); model.myProduct = p; return(View(model)); }
//[Authorize(Roles = "Admin")] // [Authorize(Roles = "Admin, User")] public ActionResult Details(int id) { Product p = new ProductServ.ProductServiceClient().GetProductByID(id); IEnumerable <Comment> c = new ProductServ.ProductServiceClient().GetCommentByProductID(id); double avgRating = new ProductServ.ProductServiceClient().getAverageRating(id); ProductModel model = new ProductModel(); model.myProduct = p; model.myComment = c.ToList(); model.averageRating = avgRating; return(View(model)); }
public ActionResult Report3(int pid) { List <FaultReport> frList = new ProductServ.ProductServiceClient().getMostFaults().ToList(); FaultReport fr = new FaultReport(); Product p = new Product(); foreach (FaultReport frr in frList) { fr = frr; } int pID = Convert.ToInt32(fr.ProductID); p = new ProductServ.ProductServiceClient().GetProductByID(pID); return(new RazorPDF.PdfResult(p, "Report3")); }
public PartialViewResult MostPurchasedItem() { List <ProductOrder> poList = new ProductServ.ProductServiceClient().getMostPurchasedItem().ToList(); ProductOrder po = new ProductOrder(); Product p = new Product(); foreach (ProductOrder poo in poList) { po = poo; } int pID = Convert.ToInt32(po.ProductID); p = new ProductServ.ProductServiceClient().GetProductByID(pID); return(PartialView("_mostPurchasedItem", p)); }
public PartialViewResult LeastFaults() { List <FaultReport> frList = new ProductServ.ProductServiceClient().getLeastFaults().ToList(); FaultReport fr = new FaultReport(); Product p = new Product(); foreach (FaultReport frr in frList) { fr = frr; } int pID = Convert.ToInt32(fr.ProductID); p = new ProductServ.ProductServiceClient().GetProductByID(pID); return(PartialView("_leastFaults", p)); }
public ActionResult Report2(int pid) { //most purchase item List <ProductOrder> poList = new ProductServ.ProductServiceClient().getMostPurchasedItem().ToList(); ProductOrder po = new ProductOrder(); Product p = new Product(); foreach (ProductOrder poo in poList) { po = poo; } int pID = Convert.ToInt32(po.ProductID); p = new ProductServ.ProductServiceClient().GetProductByID(pID); //return PartialView("_mostPurchasedItem", p); return(new RazorPDF.PdfResult(p, "Report2")); }
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); }
//public ActionResult PDF() //{ // products = new ProductServ.ProductServiceClient().GetAllProducts().ToList(); // return new RazorPDF.PdfResult(products, "PDF"); //} public ActionResult Filter(string category, string name, string lowPrice, string highPrice) { decimal parsed; try { //to check type of price //if ((category == null || category == "") && (name == null || name == "") && Decimal.TryParse(lowPrice, out parsed) && Decimal.TryParse(highPrice, out parsed) ) if (!Decimal.TryParse(lowPrice, out parsed) && !Decimal.TryParse(highPrice, out parsed)) { List <Product> pro = new ProductServ.ProductServiceClient().GetAllProducts().ToList(); TempData["Error"] = "Price needs to be of type decimal (2.00)"; return(View("ProductList", pro)); } //to check for nulls if ((category == null || category == "") && (name == null || name == "") && (lowPrice == null || lowPrice == "") && (highPrice == null || highPrice == "")) { TempData["Null"] = "One of the values is required"; // return View("ProductList", products); } if ((category != null || category != "") && (name == null || name == "") && (lowPrice == null || lowPrice == "") && (highPrice == null || highPrice == "")) { products = new ProductServ.ProductServiceClient().searchByCategory(category).ToList(); } else if ((category == null || category == "") && (name != null || name != "") && (lowPrice == null || lowPrice == "") && (highPrice == null || highPrice == "")) { products = new ProductServ.ProductServiceClient().searchByName(name).ToList(); } else if ((category == null || category == "") && (name == null || name == "") && (lowPrice != null || lowPrice != "") && (highPrice != null || highPrice != "")) { decimal lPrice = Convert.ToDecimal(lowPrice); decimal hPrice = Convert.ToDecimal(highPrice); products = new ProductServ.ProductServiceClient().searchByPriceRange(lPrice, hPrice).ToList(); } return(View("ProductList", products)); } catch (Exception ex) { TempData["CatchError"] = "An error was encountered. Please try again later"; return(View("ProductList", products)); } }
public PartialViewResult HighlyRatedItem() { List <Rating> p = new ProductServ.ProductServiceClient().getHighlyRatedItem().ToList(); Rating r = new Rating(); Product pr = new Product(); foreach (Rating rr in p) { r = rr; ViewBag.Rating = r.Rating1; } int pID = Convert.ToInt32(r.ProductID); pr = new ProductServ.ProductServiceClient().GetProductByID(pID); return(PartialView("_highlyRatedItem", pr)); //return new RazorPDF.PdfResult("ShowReport",pr.ToString()); }
public void SendEmailToClient(int accountID, Image img, int pid, MemoryStream stream, int ticketNum) { Product p = new ProductServ.ProductServiceClient().GetProductByID(pid); string username = Session["username"].ToString(); Common.User details = new UserServ.UserServiceClient().getUSerByAccountID(accountID); string body = "Dear " + "\n" + details.Name + " " + details.Surname; body += "<br />"; body += "The fault of the product" + p.Name + " has been reported and your ticket number is : " + ticketNum; body += "Also attached is your barcode."; Bitmap bm = new Bitmap(stream); bm.Save(HttpContext.Response.OutputStream, ImageFormat.Jpeg); //Attachment attachment = new Attachment(stream, "BarcodeImage.jpg"); //img.Save(stream, ImageFormat.Jpeg); stream.Position = 0; //mail.Attachments.Add(new Attachment(stream, "image/jpg")); using (MailMessage mail = new MailMessage()) { mail.From = new MailAddress(emailFrom); // mail.Attachments.Add(attachment); mail.Attachments.Add(new Attachment(stream, "Barcodeimg.jpg", "image/jpg")); mail.To.Add(details.Email); mail.Subject = subject; mail.IsBodyHtml = true; mail.Body = body; using (SmtpClient smtp = new SmtpClient(smtpAddress, portNumber)) { smtp.Credentials = new NetworkCredential(emailFrom, password); smtp.EnableSsl = enableSSL; smtp.Send(mail); } } }
// // 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")); } }
public ActionResult Report(int pid) { //highest rated item List <Rating> p = new ProductServ.ProductServiceClient().getHighlyRatedItem().ToList(); Rating r = new Rating(); Product pr = new Product(); foreach (Rating rr in p) { r = rr; ViewBag.Rating = r.Rating1; } //int pID = Convert.ToInt32(r.ProductID); int pID = Convert.ToInt32(pid); pr = new ProductServ.ProductServiceClient().GetProductByID(pID); return(new RazorPDF.PdfResult(pr, "Report")); //return View(); }
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)); } }
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); } }