Пример #1
0
        public async Task <IActionResult> Create([Bind("ProdId,SizeId,ColorId,Quantity")] ProductsQuantity productsQuantity)
        {
            if (ModelState.IsValid)
            {
                _context.Add(productsQuantity);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["ProdId"]  = new SelectList(_context.Product, "Id", "Id", productsQuantity.ProdId);
            ViewData["ColorId"] = new SelectList(_context.ProductColor, "Id", "Id", productsQuantity.ColorId);
            ViewData["SizeId"]  = new SelectList(_context.ProductSize, "Id", "Id", productsQuantity.SizeId);
            return(View(productsQuantity));
        }
        //public async Task<IActionResult> Create([Bind("CategoryId,Id,Name,Description,Price,IsTradable,CreatedAt,Images")] Product product,Image image)
        public async Task <IActionResult> Create([Bind("CategoryId,Id,Name,Description,Price,IsTradable,CreatedAt,Images")] Product product)
        {
            if (ModelState.IsValid)
            {
                if (product.Images == null)
                {
                    product.Images = new List <ProductsImages>()
                    {
                    };
                    product.Images.Add(new ProductsImages()
                    {
                        ProdId = product.Id, ColorId = 1, ImgSrc = "Poster_not_available.jpg"
                    });
                }
                product.CreatedAt = DateTime.Now;
                _context.Add(product);
                await _context.SaveChangesAsync();

                //return RedirectToAction(nameof(Index));
                var createdProd = _context.Product.LastOrDefault();
                //return RedirectToAction("CreateSpesificQuantity", "ProductsQuantities", createdProd.Id);
                return(RedirectToAction("Create", "ProductsQuantities"));
            }
            return(View(product));
        }
Пример #3
0
        public async Task <IActionResult> Create([Bind("Id,NickName,FirstName,LastName,UserType,PhoneNumber,Email,CreatedAt,UpdatedAt, Password")] User user)
        {
            if (ModelState.IsValid)
            {
                user.UserType  = UserType.Customer;
                user.CreatedAt = DateTime.Now;
                _context.Add(user);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(user));
        }
        public async Task <IActionResult> Create(Cart cart)
        {
            if (ModelState.IsValid)
            {
                _context.Add(cart);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["ProdId"]  = new SelectList(_context.Product, "Id", "Id", cart.ProdId);
            ViewData["ColorId"] = new SelectList(_context.ProductColor, "Id", "Id", cart.ColorId);
            ViewData["SizeId"]  = new SelectList(_context.ProductSize, "Id", "Id", cart.SizeId);
            ViewData["UserId"]  = new SelectList(_context.User, "Id", "Id", cart.UserId);
            return(View(cart));
        }