Пример #1
0
        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);
     }
 }
Пример #3
0
 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");
 }
Пример #4
0
 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);
 }
Пример #5
0
 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();
     }
 }
Пример #6
0
 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);
         }
     }
 }
Пример #7
0
 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();
     }
 }
Пример #8
0
 private IndexModel fillIndexModel()
 {
     IndexModel model = new IndexModel();
     DatabaseQuery db = new DatabaseQuery();
     model.Categories = db.GetCategories();
     model.Products = db.GetProducts();
     return model;
 }
Пример #9
0
        //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
        }
Пример #10
0
 public ActionResult Register(User user)
 {
     user.Prepare();
     if (ModelState.IsValid)
     {
         using (DatabaseQuery query = new DatabaseQuery())
         {
             query.CreateUser(user);
         }
         return RedirectToAction("Login");
     }
     return View(user);
 }
Пример #11
0
 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");
 }
Пример #12
0
 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);
     }
 }
Пример #13
0
 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");
 }
Пример #14
0
 public ActionResult CustomerOverview()
 {
     if (TempData["ErrorMessage"] != null)
     {
         ViewBag.Error = TempData["ErrorMessage"].ToString();
     }
     using (DatabaseQuery query = new DatabaseQuery())
     {
         return View(query.GetUsers());
     }
 }
Пример #15
0
 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");
     }
 }
Пример #16
0
 public ActionResult Preview(ulong productId)
 {
     CheckSession();
     using (DatabaseQuery querry = new DatabaseQuery())
     {
         Product product = querry.GetProduct(productId);
         return View(product);
     }
 }
Пример #17
0
 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");
 }
Пример #18
0
 public ActionResult Product()
 {
     if (TempData["ErrorMessage"] != null)
     {
         ViewBag.Error = TempData["ErrorMessage"].ToString();
     }
     using (DatabaseQuery query = new DatabaseQuery())
     {
         return View(query.GetProducts());
     }
 }
Пример #19
0
 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");
 }
Пример #20
0
        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
        }
Пример #21
0
 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();
     }
 }
Пример #22
0
 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
 }
Пример #23
0
        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);
        }
Пример #24
0
 public ActionResult UserDetails()
 {
     using (DatabaseQuery query = new DatabaseQuery())
     {
         return View(((Session)this.Session["__MySessionObject"]).User);
     }
 }
Пример #25
0
 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
 }
Пример #26
0
 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;
 }
Пример #27
0
 public ActionResult Order(ulong orderId)
 {
     CheckSession();
     Order order = new Order();
     using (DatabaseQuery query = new DatabaseQuery())
     {
         order = query.GetOrder(orderId);
     }
     return View(order);
 }