예제 #1
0
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

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

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

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

                    images.Add(new Image {
                        Link = filePath, ProductId = proid
                    });
                }
            }
            _context.Images.AddRange(images);
            await _context.SaveChangesAsync();

            return(RedirectToPage("./Index"));
        }
예제 #2
0
        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();

                mesaage = " Image uploaded successfully ";
            }
            else
            {
                error = $" please upload an image";
            }


            return(RedirectToPage("./Index"));
        }
예제 #3
0
        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"));
        }
예제 #4
0
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

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

            return(RedirectToPage("./Index"));
        }
예제 #5
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"));
        }
예제 #6
0
        public async Task <IActionResult> OnPostAsync(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

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

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

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