Esempio n. 1
0
        public async Task <IActionResult> Create([Bind("Id,FirstName,LastName,Password,PhoneNumber,Email,DateOfBirth")] Client client)
        {
            if (ModelState.IsValid)
            {
                _context.Add(client);
                await _context.SaveChangesAsync();

                return(RedirectToAction("Index", "Home"));
            }
            return(View(client));
        }
Esempio n. 2
0
        public async Task <IActionResult> Create([Bind("Id,Street,City,HouseNumber,Zip")] Address address)
        {
            if (ModelState.IsValid)
            {
                _context.Add(address);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(address));
        }
        public async Task <IActionResult> CreateCart()
        {
            if (HttpContext.Session.GetString("FirstName") == null)
            {
                return(RedirectToAction("Login", "Clients"));
            }
            if (HttpContext.Session.GetString("cart") == null)
            {
                ViewData["CartError"] = "Your cart is empty!";

                //await _context.SaveChangesAsync();
                //string myString = Id.ToString();
                //HttpContext.Session.SetString("cart", myString);

                //var purchased = from p in _context.Product
                //                where Id == p.Id
                //                select p;
                //foreach (var product in purchased)
                //{
                //    product.CartId = cart.Id;
                //    product.Cart = cart;
                //    cart.Products.Add(product);
                //}
                //string cartUnit = cart.Id.ToString();
                //HttpContext.Session.SetString("cartUnit", cartUnit);
                //return View(cart);
                return(View());
            }
            else
            {
                Cart cart;
                cart          = new Cart();
                cart.Products = new List <Product>();
                _context.Add(cart);
                await _context.SaveChangesAsync();

                string   myProduct = HttpContext.Session.GetString("cart");
                string[] ids       = myProduct.Split(',');
                int[]    myInts    = ids.Select(int.Parse).ToArray();
                var      c         = from p in _context.Product
                                     where myInts.Contains(p.Id)
                                     select p;
                foreach (var product in c)
                {
                    product.CartId = cart.Id;
                    product.Cart   = cart;
                    cart.Products.Add(product);
                }
                string cartUnit = cart.Id.ToString();
                HttpContext.Session.SetString("cartUnit", cartUnit);
            }

            return(View());
        }
        public async Task <IActionResult> Create([Bind("Id,Image,Description,price")] Product product)
        {
            if (HttpContext.Session.GetString("FirstName") != "L&G1234")
            {
                return(RedirectToAction("Login", "Clients"));
            }
            if (ModelState.IsValid)
            {
                _context.Add(product);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(product));
        }
Esempio n. 5
0
        public async Task <IActionResult> Create([Bind("Id,Name")] SubCategory subCategory)
        {
            if (HttpContext.Session.GetString("FirstName") != "L&G1234")
            {
                return(RedirectToAction("Login", "Clients"));
            }
            if (ModelState.IsValid)
            {
                _context.Add(subCategory);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(subCategory));
        }
        public async Task <IActionResult> Create([Bind("Id,Name,SubCategoryId")] Category category)
        {
            if (HttpContext.Session.GetString("FirstName") != "L&G1234")
            {
                return(RedirectToAction("Login", "Clients"));
            }
            if (ModelState.IsValid)
            {
                _context.Add(category);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["SubCategoryId"] = new SelectList(_context.Set <SubCategory>(), "Id", "Name", category.SubCategoryId);
            return(View(category));
        }
        public async Task <IActionResult> Create()
        {
            Order order = new Order();

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

            //order's cart:
            order.Cart = new Cart();
            string cartId = HttpContext.Session.GetString("cartUnit");
            int    x      = Int32.Parse(cartId);
            //order.CartId = x;
            var myCart = from chosenCart in _context.Cart
                         where chosenCart.Id == x
                         select chosenCart;

            order.Cart = (Cart)myCart;
            //order's client:
            order.Client = new Client();
            string clientId = HttpContext.Session.GetString("clientId");
            int    y        = Int32.Parse(clientId);
            var    myClient = from chosenClient in _context.Client
                              where chosenClient.Id == y
                              select chosenClient;

            order.Client = (Client)myClient;
            //order's sum:
            string sum = HttpContext.Session.GetString("price");
            float  z   = Int32.Parse(sum);

            order.Sum = z;
            await _context.SaveChangesAsync();

            //if (ModelState.IsValid)
            //{
            //    _context.Add(order);
            //    await _context.SaveChangesAsync();
            //    return RedirectToAction(nameof(Index));
            //}
            //ViewData["CartId"] = new SelectList(_context.Cart, "Id", "Id", order.CartId);
            return(View(order));
        }