public async Task <IActionResult> Create([Bind(include: "Name, Price,DiscountPrice, Photo")] NewArrival newArrival)
        {
            if (!ModelState.IsValid)
            {
                return(View(newArrival));
            }

            if (newArrival.Photo == null)
            {
                ModelState.AddModelError("Photo", "Photo can't be null...");
                return(View(newArrival));
            }

            if (!newArrival.Photo.isImage())
            {
                ModelState.AddModelError("Photo", "Photo type is not valid...");
                return(View(newArrival));
            }

            newArrival.Image = await newArrival.Photo.SaveAsync(_env.WebRootPath, "images", "asbabphotos");

            newArrival.Date = DateTime.Now;

            _context.NewArrivals.Add(newArrival);
            await _context.SaveChangesAsync();

            return(RedirectToAction("Index", "NewArrival"));
        }
        public async Task <IActionResult> Create([Bind(include: "Title, Body, Photo")] Header header)
        {
            if (!ModelState.IsValid)
            {
                return(View(header));
            }

            if (header.Photo == null)
            {
                ModelState.AddModelError("Photo", "Photo can't be null...");
                return(View(header));
            }

            if (!header.Photo.isImage())
            {
                ModelState.AddModelError("Photo", "Photo type is not valid...");
                return(View(header));
            }

            header.Image = await header.Photo.SaveAsync(_env.WebRootPath, "images", "asbabphotos");

            _context.Headers.Add(header);
            await _context.SaveChangesAsync();

            return(RedirectToAction("Index"));
        }
Ejemplo n.º 3
0
        public async Task <IActionResult> Create([Bind(include: "Name, Details, Price, Photo")] Product product, int CategoryId)
        {
            if (!ModelState.IsValid)
            {
                return(View(product));
            }

            if (product.Photo == null)
            {
                ModelState.AddModelError("Photo", "Photo can't be null...");
                return(View(product));
            }

            if (!product.Photo.isImage())
            {
                ModelState.AddModelError("Photo", "Photo type is not valid...");
                return(View(product));
            }
            product.CategoryId = CategoryId;

            product.Image = await product.Photo.SaveAsync(_env.WebRootPath, "images", "asbabphotos");

            _context.Products.Add(product);
            await _context.SaveChangesAsync();

            return(RedirectToAction("Index"));
        }
        public async Task <IActionResult> Create([Bind(include: "Title, Description, Date, Photo")] OurBlog ourBlog)
        {
            if (!ModelState.IsValid)
            {
                return(View(ourBlog));
            }

            if (ourBlog.Photo == null)
            {
                ModelState.AddModelError("Photo", "Photo can't be null...");
                return(View(ourBlog));
            }

            if (!ourBlog.Photo.isImage())
            {
                ModelState.AddModelError("Photo", "Photo type is not valid...");
                return(View(ourBlog));
            }

            ourBlog.Image = await ourBlog.Photo.SaveAsync(_env.WebRootPath, "images", "asbabphotos");

            ourBlog.Date = DateTime.Now.ToString("MMMM dd,  yyyy");
            _context.OurBlogs.Add(ourBlog);
            await _context.SaveChangesAsync();

            return(RedirectToAction("Index"));
        }
        public async Task <IActionResult> SetFavourites(string userid, int id)
        {
            UserProduct userProduct = new UserProduct();

            userProduct.ApplicationUserId = _userManager.GetUserId(User);
            userProduct.ProductId         = id;

            _context.UserProducts.Add(userProduct);
            await _context.SaveChangesAsync();

            return(Content("code = 200 "));
        }
        public async Task <IActionResult> Create([Bind(include: "Name")] Category category)
        {
            if (!ModelState.IsValid)
            {
                return(View(category));
            }

            _context.Categories.Add(category);
            await _context.SaveChangesAsync();

            return(RedirectToAction("Index", "Category"));
        }