public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

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

            var prdId  = Product.Id;
            var images = new List <Image>();

            foreach (var img in ProductImage)
            {
                if (img != null && img.Length > 0)
                {
                    var filePath = await FileUpload.UploadFile(img, "productimages");

                    images.Add(new Image {
                        Link = filePath, ProductId = prdId
                    });
                }
            }

            _context.Images.AddRange(images);
            await _context.SaveChangesAsync();


            return(RedirectToPage("./Index"));
        }
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

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

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

            return(RedirectToPage("./Index"));
        }
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            if (BannerImage != null && BannerImage.Length > 0)
            {
                var fileName = DateTime.Now.Ticks.ToString() + BannerImage.FileName;
                var filePath = Path.Combine(Directory.GetCurrentDirectory(),
                                            @"wwwroot\productimages", fileName);
                await BannerImage.CopyToAsync(new FileStream(filePath, FileMode.Create));

                SubCategory.BannerImage = fileName;

                _context.SubCategories.Add(SubCategory);
                await _context.SaveChangesAsync();

                return(RedirectToPage("./Index"));
            }
            else
            {
                Error = "Banner image is required";

                return(Page());
            }
        }
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            _context.MainCategories.Add(MainCategory);
            await _context.SaveChangesAsync();

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

            Product = await _context.Products.FindAsync(id);

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

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

            MainCategory = await _context.MainCategories.FindAsync(id);

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

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

            Address = await _context.Addresses.FindAsync(id);

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

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