public ActionResult Add(ProductViewModel productViewModel) { try { var vendor = (Clitzy.Models.Vendor)SessionPersister.account; if (ModelState.IsValid) { productViewModel.product.VendorId = vendor.Id; productViewModel.product.Views = 0; ocmde.Products.Add(productViewModel.product); ocmde.SaveChanges(); return(RedirectToAction("Index")); } var categories = ocmde.Categories.Where(c => c.VendorId == vendor.Id).Select(c => new { Id = c.Id, Name = c.Name, Group = c.Category2.Name }).ToList(); productViewModel.CategoriesMultiLevel = new SelectList(categories, "Id", "Name", "Group", 1); return(View("Add", productViewModel)); } catch (Exception e) { return(View("Error", new HandleErrorInfo(e, "Product", "Add"))); } }
public ActionResult Save() { try { if (SessionPersister.account == null) { return(RedirectToAction("Index", "Login", new { Area = "Customer" })); } else { var account = SessionPersister.account; if (account is Account && !((Clitzy.Models.Account)account).IsAdmin) { var customer = (Clitzy.Models.Account)account; List <Item> cart = (List <Item>)Session["cart"]; var vendorIds = cart.Select(i => i.product.VendorId).Distinct().ToList(); vendorIds.ForEach(id => { var currentVendor = ocmde.Vendors.Find(id); // Create new order Order order = new Order() { CustomerId = customer.Id, DateCreation = DateTime.Now, Name = Resources.Vendor.New_Order_for_Vendor + " " + currentVendor.Name, OrderStatusId = 1, VendorId = id }; ocmde.Orders.Add(order); ocmde.SaveChanges(); // Create order details cart.Where(i => i.product.VendorId == id).ToList().ForEach(i => { OrdersDetail ordersDetail = new OrdersDetail() { OrderId = order.Id, Price = i.product.Price, Quantity = i.quantity, ProductId = i.product.Id }; ocmde.OrdersDetails.Add(ordersDetail); ocmde.SaveChanges(); }); }); // Remove Cart Session.Remove("Cart"); return(RedirectToAction("Index", "Orders", new { Area = "Customer" })); } return(RedirectToAction("Index", "Login", new { Area = "Customer" })); } } catch (Exception e) { return(View("Error", new HandleErrorInfo(e, "Home", "Index"))); } }
public ActionResult Status(int id) { try { var customer = ocmde.Accounts.SingleOrDefault(a => a.Id == id); customer.Status = !customer.Status; ocmde.SaveChanges(); return(RedirectToAction("Customer", "Account")); } catch (Exception e) { return(View("Error", new HandleErrorInfo(e, "Account", "Status"))); } }
public ActionResult Edit(Clitzy.Models.Setting setting, HttpPostedFileBase logo) { try { if (logo != null && logo.ContentLength > 0 && !logo.ContentType.Contains("image")) { ViewBag.errorPhoto = Resources.Vendor.Photo_Invalid; return(View("Edit", ocmde.Settings.Find(setting.Id))); } if (ModelState.IsValid) { var currentSetting = ocmde.Settings.Find(setting.Id); if (logo != null && logo.FileName.Length != 0) { var fileName = DateTime.Now.ToString("yyyyMMddHHmmssfff") + Path.GetFileName(logo.FileName); logo.SaveAs(Path.Combine(Server.MapPath("~/Content/User/Images"), fileName)); currentSetting.Value = fileName; } else { currentSetting.Value = setting.Value; } ocmde.SaveChanges(); return(RedirectToAction("Group", "Setting", new { id = currentSetting.Group })); } return(View("Edit", setting)); } catch (Exception e) { return(View("Error", new HandleErrorInfo(e, "Setting", "Edit"))); } }
public ActionResult Register(Account account) { try { if (account.Username != null && account.Username.Length > 0) { if (Exists(account.Username)) { ModelState.AddModelError("username", Resources.Vendor.Username_already_exists); } } if (account.Password != null && account.Password.Length != 0 && !PasswordHelper.IsValidPassword(account.Password)) { ModelState.AddModelError("Password", Resources.Vendor.Password_validate_message); } if (ModelState.IsValid) { account.IsAdmin = false; account.Status = true; account.Password = BCrypt.Net.BCrypt.HashPassword(account.Password); ocmde.Accounts.Add(account); ocmde.SaveChanges(); return(RedirectToAction("Index", "Login", new { Area = "Customer" })); } else { return(View("Register", account)); } } catch (Exception e) { return(View("Error", new HandleErrorInfo(e, "Customers", "Register"))); } }
public ActionResult Add(Clitzy.Models.MemberShip memberShip) { try { if (ModelState.IsValid) { ocmde.MemberShips.Add(memberShip); ocmde.SaveChanges(); return(RedirectToAction("Index")); } return(View("Add", memberShip)); } catch (Exception e) { return(View("Error", new HandleErrorInfo(e, "MemberShip", "Add"))); } }
public ActionResult Profile(Clitzy.Models.Vendor vendor, HttpPostedFileBase logo) { try { var loginedAccount = (Clitzy.Models.Vendor)SessionPersister.account; var currentVendor = ocmde.Vendors.SingleOrDefault(a => a.Id == vendor.Id); if (vendor.Username != null && vendor.Username.Length > 0 && loginedAccount.Username != vendor.Username) { if (Exists(vendor.Username)) { ModelState.AddModelError("username", Resources.Customer.Username_exists); } } if (vendor.Password != null && vendor.Password.Length != 0 && !PasswordHelper.IsValidPassword(vendor.Password)) { ModelState.AddModelError("Password", Resources.Vendor.Password_validate_message); } if (logo != null && logo.ContentLength > 0 && !logo.ContentType.Contains("image")) { ViewBag.errorPhoto = Resources.Vendor.Photo_Invalid; return(View("Profile", loginedAccount)); } if (ModelState.IsValid) { if (vendor.Password != null && vendor.Password.Length != 0) { currentVendor.Password = BCrypt.Net.BCrypt.HashPassword(vendor.Password); } if (logo != null && logo.ContentLength > 0 && logo.ContentType.Contains("image")) { logo.SaveAs(Path.Combine(Server.MapPath("~/Content/User/Images"), Path.GetFileName(logo.FileName))); currentVendor.Logo = Path.GetFileName(logo.FileName); } currentVendor.Email = vendor.Email; currentVendor.Name = vendor.Name; currentVendor.Phone = vendor.Phone; currentVendor.Address = vendor.Address; currentVendor.Username = vendor.Username; ocmde.SaveChanges(); SessionPersister.account = ocmde.Vendors.Find(vendor.Id); return(RedirectToAction("Profile", "Login")); } else { return(View("Profile", vendor)); } } catch (Exception e) { return(View("Error", new HandleErrorInfo(e, "Login", "Profile"))); } }
public ActionResult SendMessage(Message message) { try { var customer = (Clitzy.Models.Account)SessionPersister.account; message.CustomerId = customer.Id; message.DateCreation = DateTime.Now; message.Status = false; ocmde.Messages.Add(message); ocmde.SaveChanges(); TempData["message"] = Resources.Vendor.messages_sent_success; return(RedirectToAction("SendMessage")); } catch (Exception e) { return(View("Error", new HandleErrorInfo(e, "Vendors", "SendMessage"))); } }
public ActionResult Update(FormCollection fc) { int id = int.Parse(fc["id"]); int paymentId = int.Parse(fc["payment"]); int orderStatusId = int.Parse(fc["orderStatus"]); var order = ocmde.Orders.Find(id); order.PaymentId = paymentId; order.OrderStatusId = orderStatusId; ocmde.SaveChanges(); return(RedirectToAction("Index")); }
public ActionResult Add(CategoryViewModel categoryViewModel) { try { if (ModelState.IsValid) { if (categoryViewModel.category.ParentId == -1) { categoryViewModel.category.ParentId = null; } ocmde.Categories.Add(categoryViewModel.category); ocmde.SaveChanges(); return(RedirectToAction("Index")); } return(View("Add", categoryViewModel)); } catch (Exception e) { return(View("Error", new HandleErrorInfo(e, "Category", "Add"))); } }
public ActionResult Edit(Page page) { try { if (ModelState.IsValid) { var currentPage = ocmde.Pages.Find(page.Id); currentPage.Plug = page.Plug; currentPage.Title = page.Title; currentPage.Status = page.Status; currentPage.Detail = page.Detail; ocmde.SaveChanges(); return(RedirectToAction("Index")); } return(View("Edit", page)); } catch (Exception e) { return(View("Error", new HandleErrorInfo(e, "Page", "Edit"))); } }
public ActionResult Add(CategoryViewModel categoryViewModel) { try { if (ModelState.IsValid) { var vendor = (Clitzy.Models.Vendor)SessionPersister.account; if (categoryViewModel.category.ParentId == -1) { categoryViewModel.category.ParentId = null; } categoryViewModel.category.VendorId = vendor.Id; ocmde.Categories.Add(categoryViewModel.category); ocmde.SaveChanges(); return(RedirectToAction("Index")); } return(View("Add", categoryViewModel)); } catch (Exception e) { return(View("Error", new HandleErrorInfo(e, "Category", "Add"))); } }
public ActionResult Status(int id) { try { var product = ocmde.Products.SingleOrDefault(p => p.Id == id); product.Status = !product.Status; ocmde.SaveChanges(); return(RedirectToAction("Index")); } catch (Exception e) { return(View("Error", new HandleErrorInfo(e, "Product", "Status"))); } }
#pragma warning disable CS0108 // Member hides inherited member; missing new keyword public ActionResult Profile(Clitzy.Models.Account account) #pragma warning restore CS0108 // Member hides inherited member; missing new keyword { try { var loginedAccount = (Clitzy.Models.Account)SessionPersister.account; var currentAccount = ocmde.Accounts.SingleOrDefault(a => a.Id == account.Id); if (account.Username != null && account.Username.Length > 0 && loginedAccount.Username != account.Username) { if (Exists(account.Username)) { ModelState.AddModelError("Username", Resources.Customer.Username_exists); } } if (account.Password != null && account.Password.Length != 0 && !PasswordHelper.IsValidPassword(account.Password)) { ModelState.AddModelError("Password", Resources.Vendor.Password_validate_message); } if (ModelState.IsValid) { if (account.Password != null && account.Password.Length != 0) { currentAccount.Password = BCrypt.Net.BCrypt.HashPassword(account.Password); } currentAccount.Email = account.Email; currentAccount.FullName = account.FullName; currentAccount.Phone = account.Phone; currentAccount.Username = account.Username; ocmde.SaveChanges(); SessionPersister.account = ocmde.Accounts.Find(account.Id); TempData["msg"] = Resources.Customer.Update_Success; return(RedirectToAction("Profile", "Login")); } else { return(View("Profile", account)); } } catch (Exception e) { return(View("Error", new HandleErrorInfo(e, "Login", "Profile"))); } }
public ActionResult Detail(int id) { try { var product = ocmde.Products.Find(id); if (!VendorHelper.checkExpires(product.VendorId)) { return(RedirectToAction("Expires", "Product")); } else { product.Views = product.Views + 1; ocmde.SaveChanges(); ViewBag.product = product; ViewBag.relatedProducts = ocmde.Products.Where(p => p.Id != id && p.CategoryId == product.CategoryId && p.VendorId == product.VendorId).Take(6).ToList(); return(View("Detail")); } } catch (Exception e) { return(View("Error", new HandleErrorInfo(e, "Product", "Detail"))); } }