Beispiel #1
0
        // To protect from overposting attacks, enable the specific properties you want to bind to, for
        // more details, see https://aka.ms/RazorPagesCRUD.
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                ViewData["id_category"] = new SelectList(_context.ProductCategory, "id_category", "name");
                return(Page());
            }

            _context.Attach(Product).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!ProductExists(Product.id_product))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(RedirectToPage("./Products"));
        }
Beispiel #2
0
        // To protect from overposting attacks, enable the specific properties you want to bind to, for
        // more details, see https://aka.ms/RazorPagesCRUD.
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            _context.Attach(Payment).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!PaymentExists(Payment.id_payment))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(RedirectToPage("./Index"));
        }
Beispiel #3
0
        // To protect from overposting attacks, enable the specific properties you want to bind to, for
        // more details, see https://aka.ms/RazorPagesCRUD.
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                ViewData["types"] = new SelectList(Types, user.User_Type);
                return(Page());
            }

            if (!User.HasClaim("UserType", "Admin"))
            {
                user.User_Type = "User";
            }
            List <User> list = await _context.User.ToListAsync();

            user.id_user = list.Count() > 0 ? list.Last().id_user + 1 : 1;


            try
            {
                PasswordHasher <string> passwordHasher = new PasswordHasher <string>();
                string hash = passwordHasher.HashPassword(user.login, user.password);
                user.password = hash;

                _context.User.Add(user);
                await _context.SaveChangesAsync();
            }
            catch (Exception ex)
            {
                // throw;
                loginValid = true;
                emailValid = true;
                var dbEx  = ex as DbUpdateException;
                var sqlEx = dbEx?.InnerException as SqlException;
                if (sqlEx != null)
                {
                    if (sqlEx.Number == 2601 || sqlEx.Number == 2627)
                    {
                        if (sqlEx.Message.Contains("Indx_Unique"))
                        {
                            loginValid = false;
                        }
                        if (sqlEx.Message.Contains("Mail_Unique"))
                        {
                            emailValid = false;
                        }
                        return(Page());
                    }
                    else
                    {
                        throw;
                    }
                }
                else
                {
                    throw;
                }
            }
            TempData["userId"] = user.id_user;
            return(RedirectToPage("/Customers/Create"));
        }
Beispiel #4
0
        // To protect from overposting attacks, enable the specific properties you want to bind to, for
        // more details, see https://aka.ms/RazorPagesCRUD.
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            if (User.HasClaim("UserType", "User") || User.HasClaim("UserType", "Seller"))
            {
                Adress.Customer_Id_customer = (int)TempData["customerId"];
            }
            _context.Attach(Adress).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!AdressExists(Adress.id_adress))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(RedirectToPage("./Index"));
        }
Beispiel #5
0
        // To protect from overposting attacks, enable the specific properties you want to bind to, for
        // more details, see https://aka.ms/RazorPagesCRUD.
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            _context.Attach(Customer).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!CustomerExists(Customer.id_customer))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            if (!User.HasClaim("UserType", "Admin"))
            {
                return(RedirectToPage("/UsersPanel/Index"));
            }

            return(RedirectToPage("./Index"));
        }
Beispiel #6
0
        // To protect from overposting attacks, enable the specific properties you want to bind to, for
        // more details, see https://aka.ms/RazorPagesCRUD.
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            _context.Product_Order.Add(Product_Order);
            await _context.SaveChangesAsync();

            return(RedirectToPage("./Index"));
        }
Beispiel #7
0
        // To protect from overposting attacks, enable the specific properties you want to bind to, for
        // more details, see https://aka.ms/RazorPagesCRUD.
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }


            List <Delivery_Service> list = await _context.Delivery_Service.ToListAsync();

            Delivery_Service.id_deliverman = list.Count() > 0 ? list.Last().id_deliverman + 1 : 1;

            _context.Delivery_Service.Add(Delivery_Service);
            await _context.SaveChangesAsync();

            return(RedirectToPage("./Index"));
        }
Beispiel #8
0
        // To protect from overposting attacks, enable the specific properties you want to bind to, for
        // more details, see https://aka.ms/RazorPagesCRUD.
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }


            List <Order> list = await _context.Order.ToListAsync();

            Order.id_order = list.Count() > 0 ? list.Last().id_order + 1 : 1;

            _context.Order.Add(Order);
            await _context.SaveChangesAsync();

            return(RedirectToPage("./Index"));
        }
Beispiel #9
0
        public async Task <IActionResult> OnPostAsync(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            Delivery_Service = await _context.Delivery_Service.FindAsync(id);

            if (Delivery_Service != null)
            {
                _context.Delivery_Service.Remove(Delivery_Service);
                await _context.SaveChangesAsync();
            }

            return(RedirectToPage("./Index"));
        }
Beispiel #10
0
        public async Task <IActionResult> OnPostAsync(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            Product_Category = await _context.ProductCategory.FindAsync(id);

            if (Product_Category != null)
            {
                _context.ProductCategory.Remove(Product_Category);
                await _context.SaveChangesAsync();
            }

            return(RedirectToPage("./Index"));
        }
Beispiel #11
0
        public async Task <IActionResult> OnPostAsync(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            Payment = await _context.Payment.FindAsync(id);

            if (Payment != null)
            {
                _context.Payment.Remove(Payment);
                await _context.SaveChangesAsync();
            }

            return(RedirectToPage("./Index"));
        }
Beispiel #12
0
        // To protect from overposting attacks, enable the specific properties you want to bind to, for
        // more details, see https://aka.ms/RazorPagesCRUD.
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }


            List <Product_Category> list = await _context.ProductCategory.ToListAsync();

            Product_Category.id_category = list.Count() > 0 ? list.Last().id_category + 1 : 1;

            _context.ProductCategory.Add(Product_Category);
            await _context.SaveChangesAsync();

            return(RedirectToPage("./Index"));
        }
Beispiel #13
0
        public async Task <IActionResult> OnPostAsync(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            User = await _context.User.FindAsync(id);

            if (User != null)
            {
                _context.User.Remove(User);
                await _context.SaveChangesAsync();
            }

            return(RedirectToPage("./Index"));
        }
Beispiel #14
0
        // To protect from overposting attacks, enable the specific properties you want to bind to, for
        // more details, see https://aka.ms/RazorPagesCRUD.
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }



            List <Payment> list = await _context.Payment.ToListAsync();

            Payment.id_payment = list.Count() > 0 ? list.Last().id_payment + 1 : 1;

            _context.Payment.Add(Payment);
            await _context.SaveChangesAsync();

            return(RedirectToPage("./Index"));
        }
Beispiel #15
0
        // To protect from overposting attacks, enable the specific properties you want to bind to, for
        // more details, see https://aka.ms/RazorPagesCRUD.
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                ViewData["name"] = new SelectList(_context.ProductCategory, "id_category", "name");
                return(Page());
            }


            List <Product> list = await _context.Product.ToListAsync();

            Product.id_product = list.Count() > 0 ? list.Last().id_product + 1 : 1;

            _context.Product.Add(Product);
            await _context.SaveChangesAsync();

            return(RedirectToPage("./Products"));
        }
Beispiel #16
0
        // To protect from overposting attacks, enable the specific properties you want to bind to, for
        // more details, see https://aka.ms/RazorPagesCRUD.
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            if (User.HasClaim("UserType", "User") || User.HasClaim("UserType", "Seller"))
            {
                Adress.Customer_Id_customer = (int)TempData["customerId"];
            }

            List <Adress> list = await _context.Adress.ToListAsync();

            Adress.id_adress = list.Count() > 0 ? list.Last().id_adress + 1 : 1;

            _context.Adress.Add(Adress);
            await _context.SaveChangesAsync();

            return(RedirectToPage("./Index"));
        }
Beispiel #17
0
        // To protect from overposting attacks, enable the specific properties you want to bind to, for
        // more details, see https://aka.ms/RazorPagesCRUD.
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }
            Customer.User_id_user = (int)TempData["userId"];

            List <Customer> list = await _context.Customer.ToListAsync();

            Customer.id_customer = list.Count() > 0 ? list.Last().id_customer + 1 : 1;


            _context.Customer.Add(Customer);
            await _context.SaveChangesAsync();

            if (!User.HasClaim("UserType", "Admin"))
            {
                return(RedirectToPage("/Login/UserLogin"));
            }

            return(RedirectToPage("./Index"));
        }
Beispiel #18
0
        public async Task <IActionResult> OnPostPlaceAsync()
        {
            users = await _context.User.ToListAsync();

            customers = await _context.Customer.ToListAsync();

            #region get Customer ID - I wish i could make it better ( I can but i wont atm)


            if (User.Identity.IsAuthenticated)
            {
                var identity = (ClaimsIdentity)User.Identity;
                IEnumerable <Claim> claims = identity.Claims;
                login = User.Identity.Name;
                Data.User user = users.Find(user => user.login.Equals(login));
                customer_ID = customers.Find(customer => customer.User_id_user == user.id_user).id_customer;
            }
            #endregion
            var descriptions = _context.Adress.Where(a => a.Customer_Id_customer == customer_ID).Select(a => new { id_adress = a.id_adress, Description = string.Format("City:{0} Street:{1} {2}", a.city, a.street, a.street_no) }).ToList();

            adresses = await _context.Adress.Where(a => a.Customer_Id_customer == customer_ID).ToListAsync();

            if (!ModelState.IsValid)
            {
                ViewData["adresses"] = new SelectList(adresses, "descriptions", "Description");

                return(Page());
            }

            //Fields init
            List <Order> orders = await _context.Order.AsNoTracking().ToListAsync();

            List <Payment> payments = await _context.Payment.ToListAsync();

            List <Delivery_Service> delivery_Services = await _context.Delivery_Service.ToListAsync();


            #region setting row fields
            //Order ID
            Order.id_order = orders.Count > 0 ? orders.Last().id_order + 1 : 1;
            StringBuilder stringBuilder = new StringBuilder();
            Adress        temp          = adresses.Find(a => a.Customer_Id_customer == customer_ID);
            stringBuilder.AppendJoin(':', temp.city, temp.street, temp.street_no.ToString());
            Order.orderAddress = stringBuilder.ToString();

            //Payment Fields
            payment.id_payment     = payments.Count > 0 ? payments.Last().id_payment + 1 : 1;
            payment.Order_id_order = Order.id_order;
            payment.due_date       = Order.due_date.AddDays(3d);

            //Payment ID
            Order.Payment_id_payment = payment.id_payment;

            //Delivery Service Fields
            delivery_service.id_deliverman  = delivery_Services.Count > 0 ? delivery_Services.Last().id_deliverman + 1 : 1;
            delivery_service.Order_id_order = Order.id_order;
            delivery_service.delivery_date  = Order.due_date;

            //Delivery ID
            Order.Delivery_Service_id_deliveryman = delivery_service.id_deliverman;

            #endregion

            //Please do not touch the order in which rows are added
            _context.Order.Add(Order);
            await _context.SaveChangesAsync();

            _context.Add(delivery_service);
            await _context.SaveChangesAsync();


            //the stupid tables which i hate
            customer_order.Customer_id_customer = customer_ID;
            customer_order.Order_id_order       = Order.id_order;

            _context.Add(payment);
            await _context.SaveChangesAsync();

            _context.Add(customer_order);
            await _context.SaveChangesAsync();

            //Parse Shopping cart cookie
            parseProducts();

            //Add one product Order for each prodcut type, sice DB architecture wont allow for quantity
            foreach (KeyValuePair <int, int> pair in ShoppingCart)
            {
                _context.Product_Order.Add(new Product_Order()
                {
                    Order_id_order = Order.id_order, Product_id_product = pair.Key, Count = pair.Value
                });
                await _context.SaveChangesAsync();
            }

            return(RedirectToPage("/Index"));
        }