public ActionResult Contact(ContactPageModel model) { if (ModelState.IsValid) { string messageSubject = "Message from: " + model.Email; string content = System.IO.File.ReadAllText(System.Web.HttpContext.Current.Server.MapPath("~/Mail Templates/ContactMailTemplate.html")); // look into file to understand where parameters are string message = string.Format(content, model.Name, model.Message); try { EmailSender.SendHtmlEmailTo("*****@*****.**", messageSubject, message); PZLogger.GetInstance().Info("HOME_CONTROLLER::Mail from " + model.Email + " successful sent"); return(View("ContactThanks")); } catch (Exception e) { PZLogger.GetInstance().Error("HOME_CONTROLLER::" + e.Message); return(View("~/Views/Shared/Error.cshtml")); } } else { return(View(model)); } }
public PartialViewResult ProductsRow(string category, int page = 1) { try { ProductsPagesViewModel model = new ProductsPagesViewModel { Products = repository.Products .Where(p => category == null || p.Categories.FirstOrDefault().Name == category) .OrderBy(product => product.ProductID) .Skip((page - 1) * pageSize) .Take(pageSize), /*for PageLinks helper on View*/ PagingInfo = new PagingInfo { CurrentPage = page, ItemsPerPage = pageSize, TotalItems = category == null? repository.Products.Count() : repository.Products.Where(p => p.Categories.FirstOrDefault().Name == category).Count() }, CurrentCategory = category }; return(PartialView(model)); } catch (Exception e) { PZLogger.GetInstance().Error("PARTIAL_CONTROLLER::" + e.ToString()); return(PartialView("~/Views/Shared/ErrorPartial.cshtml")); } }
public ActionResult CreateProduct(ProductViewModel productViewModel, HttpPostedFileBase productImg) { if (ModelState.IsValid) { Product product = ProductViewModelHelpers.ToDomainModel(productViewModel); //save image on the server and write path to it to the product object if (productImg != null) { try { product = loadAndBindImage(product, productImg); PZLogger.GetInstance().Info("ADMIN_CONTROLLER::Image for " + product.Name + " has been saved."); } catch (Exception e) { PZLogger.GetInstance().Error("ADMIN_CONTROLLER::Image load error: " + e.Message); return(View("~/Views/Shared/Error.cshtml")); } } AddOrUpdateCategories(product, productViewModel.Categories); productRepository.SaveProduct(product); TempData["message"] = string.Format("Product \"{0}\" are successful created", product.Name); } else { return(View(productViewModel)); } return(RedirectToAction("Index")); }
public ViewResult Checkout(Cart cart, OrderDetails orderDetails) { if (cart.Lines.Count() == 0) { ModelState.AddModelError("", "Sorry, but your cart is empty!"); } if (ModelState.IsValid) { string messageSubject = "Order to: " + orderDetails.Name + "@" + orderDetails.Email; string content = System.IO.File.ReadAllText(System.Web.HttpContext.Current.Server.MapPath("~/Mail Templates/OrderMailTemplate.html")); StringBuilder orderHTML = new StringBuilder(); foreach (var line in cart.Lines) { var subtotal = line.Product.Price * line.Quantity; orderHTML.AppendFormat("<h3>{0} x {1} || (total: {2:c})</h3>", line.Product.Name, line.Quantity, subtotal); } orderHTML.AppendFormat("<h2>Total cost: {0:c}</h2>", cart.ComputeTotalValue()); // look into file to understand where parameters are string message = string.Format(content, orderDetails.Email, orderDetails.Name, orderDetails.Adress, orderDetails.City, orderDetails.Country, orderHTML); try { EmailSender.SendHtmlEmailTo("*****@*****.**", messageSubject, message); PZLogger.GetInstance().Info("CART_CONTROLLER::Order from " + orderDetails.Email + " has been accepted."); cart.Clear(); return(View("Completed")); } catch (Exception e) { PZLogger.GetInstance().Error("HOME_CONTROLLER::" + e.Message); return(View("~/Views/Shared/Error.cshtml")); } } else { return(View(orderDetails)); } }
public ActionResult Register(RegisterModel model) { if (ModelState.IsValid) { Customer customer = null; customer = customerRepository.Customers.FirstOrDefault(c => c.Email == model.Email); if (customer == null) { customerRepository.SaveCustomer(CustomerViewModelHelpers.ToDomainModel(model)); customer = customerRepository.Customers.Where(c => c.Email == model.Email && c.Password == model.Password).FirstOrDefault(); if (customer != null) { string messageSubject = "Email Confirmation"; string content = System.IO.File.ReadAllText(System.Web.HttpContext.Current.Server.MapPath("~/Mail Templates/RegisterMailTemplate.html")); string message = string.Format(content, Url.Action("ConfirmEmail", "Authorization", new { Token = customer.CustomerID, Email = customer.Email }, Request.Url.Scheme)); try { EmailSender.SendHtmlEmailTo(customer.Email, messageSubject, message, "C:\\Users\\Daniel Martin\\Desktop\\PZStore\\project\\PZStore\\Assets\\images\\master-page\\logo.png", "logo"); PZLogger.GetInstance().Info("AUTHORIZATION_CONTROLLER::Verification email to " + customer.Email + " has been sent."); return(RedirectToAction("CongratsRegister")); } catch (Exception e) { PZLogger.GetInstance().Error("AUTHORIZATION_CONTROLLER::" + e.Message); return(View("~/Views/Shared/Error.cshtml")); } } } else { ModelState.AddModelError("existEmail", "User with the same email is already exist"); return(PartialView(model)); } } return(View(model)); }
public ActionResult ProfileDetails(Customer model, HttpPostedFileBase userImg) { if (ModelState.IsValid) { Customer customer = customerRepository.Customers.FirstOrDefault(c => c.Email == model.Email); customer.FirstName = model.FirstName; customer.LastName = model.LastName; customer.Country = model.Country; customer.Password = model.Password; customer.Phone = model.Phone; if (userImg != null) { //delete previous image before load the new one string path = Server.MapPath(customer.Image); FileInfo file = new FileInfo(path); if (file.Exists) { file.Delete(); } try { customer = loadAndBindImage(customer, userImg); PZLogger.GetInstance().Info("ACCOUNT_CONTROLLER::Image for " + customer.FirstName + " " + customer.LastName + " has been saved."); } catch (Exception e) { PZLogger.GetInstance().Error("ACCOUNT_CONTROLLER::Image load error: " + e.Message); return(View("~/Views/Shared/Error.cshtml")); } } customerRepository.SaveCustomer(customer); TempData["message"] = string.Format("Detail of \"{0}\" are successful changed", customer.FirstName); return(RedirectToAction("ProfileDetails", new { customerEmail = customer.Email })); } else { return(View(model)); } }