public ActionResult AddProductToShoppingbag(ulong productId) { CheckSession(); if (TempData["ErrorMessage"] != null) { ViewBag.Error = TempData["ErrorMessage"].ToString(); } bool amountChanged = false; Session ses = ((Session)this.Session["__MySessionObject"]); foreach (OrderLine ol in ses.ShoppingBag.OrderLines) { if (ol.Product.Id == productId) { ol.Amount++; amountChanged = true; } } if (!amountChanged) { using (DatabaseQuery query = new DatabaseQuery()) { Product product = query.GetProduct(productId); OrderLine ol = new OrderLine(); ol.Product = product; ol.Amount = 1; ses.ShoppingBag.OrderLines.Add(ol); } } this.Session["__MySessionObject"] = ses; return RedirectToAction("Products", "Home"); }
//Zoekresultaat kan een aantal producten hebben public SearchResultModel(string searchFor) { if (string.IsNullOrWhiteSpace(searchFor)) { //Er kan niet worden gezocht op een Whiet SPace throw new System.Exception("Er kan niet worden gezocht voor een leeg zoekresultaat of een spatiebalkteken"); } using (DatabaseQuery querry = new DatabaseQuery()) { //Haal alle producten op waar naar is gezocht met de SearchFor Variabele Products = querry.GetProducts(searchFor); } }
public ActionResult OrderStatusChanged(ulong orderId, OrderStatus status) { try { using (DatabaseQuery query = new DatabaseQuery()) { Order order = query.GetOrder(orderId); order.Status = status; query.UpdateOrderStatus(order); } } catch (Exception e) { TempData["ErrorMessage"] = "Er is iets fout gegaan met het schrijven naar de database: " + e; } return RedirectToAction("Orders", "Home"); }
public ActionResult PayOrder(ulong orderId) { CheckSession(); PayOrderViewModel model = new PayOrderViewModel(); using (DatabaseQuery query = new DatabaseQuery()) { List<PaymentOption> paymentOptions = query.GetPaymentOptions(); model.PaymentOptions = new SelectList(paymentOptions, "id", "name"); model.Order = query.GetOrder(orderId); } return View(model); }
public ActionResult ChangeCategory(ulong categoryId) { try { using (DatabaseQuery query = new DatabaseQuery()) { Category category = query.GetCategory(categoryId); return View(category); } } catch (Exception e) { ViewBag.Error = "Er is iets fout gegaan met het ophalen van de category: " + e; return View(); } }
public ActionResult Orders() { CheckSession(); if (TempData["ErrorMessage"] != null) { ViewBag.Error = TempData["ErrorMessage"].ToString(); } Session session = ((Session)this.Session["__MySessionObject"]); if (session.User.Role == UserRole.ADMIN) { using (DatabaseQuery query = new DatabaseQuery()) { List<Order> orders = query.GetOrders(); return View(orders); } } else { using (DatabaseQuery query = new DatabaseQuery()) { List<Order> orders = query.GetOrdersByUser(session.User); return View(orders); } } }
public ActionResult ChangeUser(ulong id) { try { using (DatabaseQuery query = new DatabaseQuery()) { User user = query.GetUser(id); return View(user); } } catch (Exception e) { ViewBag.Error = "Er is iets fout gegaan met het ophalen van de gebruiker: " + e; return View(); } }
private IndexModel fillIndexModel() { IndexModel model = new IndexModel(); DatabaseQuery db = new DatabaseQuery(); model.Categories = db.GetCategories(); model.Products = db.GetProducts(); return model; }
//nullable int public ActionResult Make_Order(ulong? Id) { if (Id != null) { ulong productId = (ulong)Id; using (DatabaseQuery productQuerry = new DatabaseQuery()) { Product product = productQuerry.GetProduct(productId); if (product != null) //ALs er een product is { Session session = (Session)this.Session["__MySessionObject"]; { using (DatabaseQuery purcasheQuery = new DatabaseQuery()) { //Maak een purchase SQL query } RedirectToAction("ProductAdded", "Home"); } } else //Redirect naar de home anlshet niet lukt { RedirectToAction("Login", "home"); } } } return RedirectToAction("Index", "Home"); //als het wel lukt dan redirect je naar home }
public ActionResult Register(User user) { user.Prepare(); if (ModelState.IsValid) { using (DatabaseQuery query = new DatabaseQuery()) { query.CreateUser(user); } return RedirectToAction("Login"); } return View(user); }
public ActionResult DeleteProduct(ulong productId) { try { using (DatabaseQuery query = new DatabaseQuery()) { query.DeleteProduct(productId); } } catch (Exception e) { TempData["ErrorMessage"] = "Er is iets fout gegaan met het verwijderen van het product: " + e; } return RedirectToAction("product"); }
public ActionResult LoginRequest(LoginDataModel user) { if (ModelState.IsValid) { using (DatabaseQuery query = new DatabaseQuery()) { PBKDF2Password password = query.GetPassword(user); //vraag het password van een gebruiker if (password != null) { //als het password niet leeg is match het password met de Database PasswordMatcher matcher = new PasswordMatcher(password, user.Password, false); //False kijkt of het interne wachtwoord gedisposed moet worden als hij gematched is. if (matcher.IsMatch) //Als een match is { try {//Probeer een Sessie te maken Session session = (Session)this.Session["__MySessionObject"]; using (DatabaseQuery userQuery = new DatabaseQuery()) { session.User = userQuery.GetUser(user); //Klant krijgt een sessie session.LoggedIn = true; this.Session["__MySessionObject"] = session; List<Order> orders = userQuery.GetOrdersByUser(session.User); foreach(Order order in orders) { if (order.Status == OrderStatus.TOBEPAID) { double days = (DateTime.Now - order.DTime).TotalDays; if (days > 14) { order.Status = OrderStatus.EXPIRED; userQuery.UpdateOrderStatus(order); } } } } if (((Session)this.Session["__MySessionObject"]).User.Role == UserRole.MANAGER) { return RedirectToAction("manage"); //Ga naar manager pagina } else if (((Session)this.Session["__MySessionObject"]).User.Role == UserRole.ADMIN) { return RedirectToAction("admin"); //Ga naar manager pagina } else if(((Session)this.Session["__MySessionObject"]).ShoppingBag.OrderLines.Count > 0) { return RedirectToAction("Shoppingbag"); } return RedirectToAction("Index"); //Ga terug naar de index } catch(Exception e) { TempData["ErrorMessage"] = "Er is iets fout gegaan met het inloggen: " + e; } } } TempData["ErrorMessage"] = "Gebruikersnaam en wachtwoord combinatie zijn onbekend"; return RedirectToAction("login", user); //redirect to faillure } } else { TempData["ErrorMessage"] = "Gebruikersnaam en/of wachtwoord combinatie is fout"; return RedirectToAction("Login", "Home", user); } }
public ActionResult DeleteCategory(ulong categoryId) { try { using (DatabaseQuery query = new DatabaseQuery()) { query.DeleteCategory(categoryId); } } catch (Exception e) { TempData["ErrorMessage"] = "Er is iets fout gegaan met het verwijderen van de categorie: " + e; } return RedirectToAction("CategoryOverview"); }
public ActionResult CustomerOverview() { if (TempData["ErrorMessage"] != null) { ViewBag.Error = TempData["ErrorMessage"].ToString(); } using (DatabaseQuery query = new DatabaseQuery()) { return View(query.GetUsers()); } }
public ActionResult CreateOrder() { CheckSession(); Session session = ((Session)this.Session["__MySessionObject"]); if (session.User != null) { Order order = new Order(); order.DTime = DateTime.Now; order.OrderLines = session.ShoppingBag.OrderLines; order.User = session.User; order.Status = OrderStatus.TOBEPAID; using (DatabaseQuery query = new DatabaseQuery()) { query.CreateOrder(order); } session.ShoppingBag = new ShoppingBag(); return RedirectToAction("Account", "Home"); } else { return RedirectToAction("Login", "Home"); } }
public ActionResult Preview(ulong productId) { CheckSession(); using (DatabaseQuery querry = new DatabaseQuery()) { Product product = querry.GetProduct(productId); return View(product); } }
public ActionResult UpdateCategory(Category category) { try { using (DatabaseQuery query = new DatabaseQuery()) { if (ModelState.IsValid) //check of de modelstate goed is { query.UpdateCategory(category); return RedirectToAction("CategoryOverview"); } } } catch (Exception e) { ViewBag.Error = "Er is iets fout gegaan met het updaten van de categorie: " + e; return RedirectToAction("ChangeCategory", category); } return RedirectToAction("category"); }
public ActionResult Product() { if (TempData["ErrorMessage"] != null) { ViewBag.Error = TempData["ErrorMessage"].ToString(); } using (DatabaseQuery query = new DatabaseQuery()) { return View(query.GetProducts()); } }
public ActionResult UpdateUser(User user) { try { user.Prepare(); //if (TryUpdateModel(user, null, null, new[] { "Password" })) --> werkt niet using (DatabaseQuery query = new DatabaseQuery()) { if (ModelState.IsValid) //is niet goed door password (wordt ofc niet opgehaald + password moet los aangepast kunnen worden) { query.UpdateUser(user); ((Session)this.Session["__MySessionObject"]).User = query.GetUser(user.Id); return RedirectToAction("UserDetails"); } } } catch (Exception e) { ViewBag.Error = "Er is iets fout gegaan met het updaten van de gebruiker: " + e; return RedirectToAction("ChangeUser", user); } return RedirectToAction("UserDetails"); }
public ActionResult Manage() { try { ManagerViewModel viewModel = new ManagerViewModel(); DatabaseQuery dbq = new DatabaseQuery(); viewModel.Orders = dbq.GetOrders(); viewModel.Orderlines = dbq.GetOrderlines(); viewModel.OrderlinesAsc = dbq.GetOrderlines(); List<Product> products = dbq.GetProducts(); foreach (Product p in products) { if (viewModel.Orderlines.Any(ol => ol.Product.Id == p.Id)) { continue; } OrderLine o = new OrderLine { Product = p, Amount = 0 }; viewModel.OrderlinesAsc.Add(o); } viewModel.OrderlinesAsc.Reverse(); //take first 10 items from list viewModel.OrderlinesAsc.Take(10); viewModel.Orderlines.Take(10); return View(viewModel); } catch (Exception e) { ViewBag.Error = "Er is iets fout gegaan met het ophalen van de producten: " + e; return View(); } //return RedirectToAction("View", "Home"); //Return naar de Homepage }
public ActionResult ChangeProduct(ulong productId) { try { using (DatabaseQuery query = new DatabaseQuery()) { ProductViewModel pvm = FillProductViewModel(); pvm.Product = query.GetProduct(productId); pvm.SelectedCategoryId = pvm.Product.Category.Id; return View(pvm); } } catch (Exception e) { ViewBag.Error = "Er is iets fout gegaan met het ophalen van het product: " + e; return View(); } }
public ActionResult UpdateProduct(ProductViewModel model) { try { using (DatabaseQuery query = new DatabaseQuery()) { model.Product.Category = query.GetCategory(model.SelectedCategoryId); if (ModelState.IsValid & (model.Product.Category != null)) //check of de modelstate goed is { query.UpdateProduct(model.Product); return RedirectToAction("Product"); } } } catch (Exception e) { ViewBag.Error = "Er is iets fout gegaan met het updaten van het product: " + e; return RedirectToAction("ChangeProduct", model.Product.Id); //Ga terug naar de Add_product pagina } return RedirectToAction("product"); //Ga terug naar de Add_product pagina }
public ActionResult NewCategory(Category category) { try { if (ModelState.IsValid) //check of de modelstate goed is { using (DatabaseQuery query = new DatabaseQuery()) { query.CreateCategory(category); return RedirectToAction("index"); //Laat de Admin zien als het goed gaat } } } catch (Exception error) { ModelState.AddModelError("Product is niet toegevoegd aan de Database", error); //Adds a model error to the errors collection for the model-state dictionary. } return RedirectToAction("AddCategory", category); }
public ActionResult UserDetails() { using (DatabaseQuery query = new DatabaseQuery()) { return View(((Session)this.Session["__MySessionObject"]).User); } }
public ActionResult NewProduct(ProductViewModel model) { try { using (DatabaseQuery query = new DatabaseQuery()) { model.Product.Category = query.GetCategory(model.SelectedCategoryId); if (ModelState.IsValid & (model.Product.Category != null)) //check of de modelstate goed is { query.CreateProduct(model.Product); return RedirectToAction("product"); //Laat de Admin zien als het goed gaat } } } catch(Exception error) { ModelState.AddModelError("Product is niet toegevoegd aan de Database" , error); //Adds a model error to the errors collection for the model-state dictionary. } return RedirectToAction("AddProduct", model); //Ga terug naar de Add_product pagina }
private ProductViewModel FillProductViewModel() { ProductViewModel model = new ProductViewModel(); DatabaseQuery dbq = new DatabaseQuery(); List<Category> categories = dbq.GetCategories(); model.Categories = new SelectList(categories, "id", "name"); return model; }
public ActionResult Order(ulong orderId) { CheckSession(); Order order = new Order(); using (DatabaseQuery query = new DatabaseQuery()) { order = query.GetOrder(orderId); } return View(order); }