示例#1
0
        public async Task <IActionResult> EditProduct(int id, IshopProduct ishopProduct)
        {
            if (id != ishopProduct.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(ishopProduct);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!IshopProductExists(ishopProduct.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(IndexProduct)));
            }
            return(View(ishopProduct));
        }
示例#2
0
        public async Task <IActionResult> CreateProduct(IshopProduct ishopProduct, IFormFile FeaturedImage, IFormFile ProPic2, IFormFile[] ProdGallery)
        {
            if (ModelState.IsValid)
            {
                var findCatCount = _context.IshopProduct.Where(a => a.ProdName == ishopProduct.ProdName).Count();
                if (findCatCount > 0)
                {
                    ViewBag.messageError = "Product Aleady Exists!!!!!";
                    ViewBag.cateorylist  = ListSubCategories();
                    return(View(ishopProduct));
                }

                ishopProduct.ProdFeatureImg = await HelperFtn.UploadProductImage(FeaturedImage);

                ishopProduct.ProPic2 = await HelperFtn.UploadProductImage(ProPic2);

                var prodGallery = await HelperFtn.UploadGalleryProductImages(ProdGallery, HttpContext.Session.GetString("SessionUsername"));

                ishopProduct.AddedBy   = HttpContext.Session.GetString("SessionUsername");
                ishopProduct.AddedDate = DateTime.Now;
                _context.Add(ishopProduct);
                await _context.SaveChangesAsync();

                if (prodGallery.Count() > 0)
                {
                    foreach (var item in prodGallery)
                    {
                        item.ProdId = ishopProduct.Id;
                    }
                    _context.AddRange(prodGallery);
                    await _context.SaveChangesAsync();
                }

                return(RedirectToAction(nameof(IndexProduct)));
            }
            ViewBag.cateorylist = ListSubCategories();
            return(View(ishopProduct));
        }