Example #1
0
        public async Task <IActionResult> Update(int?id, BigSlider bigSlider)
        {
            if (id == null)
            {
                return(NotFound());
            }
            BigSlider dbBigSlider = await _db.BigSliders.FindAsync(id);

            if (bigSlider == null)
            {
                return(NotFound());
            }

            if (ModelState["Title"].ValidationState == ModelValidationState.Invalid ||
                ModelState["Description"].ValidationState == ModelValidationState.Invalid ||
                ModelState["Link"].ValidationState == ModelValidationState.Invalid)
            {
                return(View(bigSlider));
            }

            if (bigSlider.UpdatePhoto != null)
            {
                if (!bigSlider.UpdatePhoto.IsImage())
                {
                    ModelState.AddModelError("UpdatePhoto", "You can choose only Image Format");
                    return(View());
                }
                if (!bigSlider.UpdatePhoto.CheckSize(2))
                {
                    ModelState.AddModelError("UpdatePhoto", "You can choosen only small at 2mb");
                    return(View());
                }

                string filename = await bigSlider.UpdatePhoto.CopyImage(_env.WebRootPath, "slider");

                Assistant.DeleteFromFolder(_env.WebRootPath, dbBigSlider.Image);
                dbBigSlider.Image = filename;
            }

            dbBigSlider.Title       = bigSlider.Title;
            dbBigSlider.Description = bigSlider.Description;
            dbBigSlider.Link        = bigSlider.Link;
            await _db.SaveChangesAsync();

            return(RedirectToAction(nameof(Index)));
        }
Example #2
0
        public async Task <IActionResult> Update(int?id, Brand brand)
        {
            if (id == null)
            {
                return(NotFound());
            }
            Brand dbbrand = await _db.Brands.FindAsync(id);

            if (brand == null)
            {
                return(NotFound());
            }
            //if (dbbrand.Id != null) return Content($"{dbbrand.Id}");

            if (ModelState["Photo"].ValidationState == ModelValidationState.Invalid)
            {
                return(RedirectToAction(nameof(Index)));
            }

            if (brand.Photo != null)
            {
                if (!brand.Photo.IsImage())
                {
                    ModelState.AddModelError("Photo", "You can Cchose only image");
                    return(View());
                }

                if (!(brand.Photo.CheckSize(2)))
                {
                    ModelState.AddModelError("Photo", "You Can choos Image a little than 2 MB");
                    return(View());
                }

                string createdPath = await brand.Photo.CopyImage(_env.WebRootPath, "brand");

                Assistant.DeleteFromFolder(_env.WebRootPath, dbbrand.Path);
                dbbrand.Path = createdPath;
            }

            await _db.SaveChangesAsync();

            return(RedirectToAction(nameof(Index)));
        }
        public async Task <IActionResult> DeletePost(int?id)
        {
            if (id == null)
            {
                return(Content("Id tapilmadiq"));
            }
            WeekCategory weekcategory = await _db.WeekCategories.FindAsync(id);

            if (weekcategory == null)
            {
                return(NotFound());
            }

            Assistant.DeleteFromFolder(_env.WebRootPath, weekcategory.Image);
            _db.WeekCategories.Remove(weekcategory);
            await _db.SaveChangesAsync();

            return(RedirectToAction(nameof(Index)));
        }
Example #4
0
        public async Task <IActionResult> DeletePost(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }
            BigSlider bigSlider = await _db.BigSliders.FindAsync(id);

            if (bigSlider == null)
            {
                return(NotFound());
            }

            Assistant.DeleteFromFolder(_env.WebRootPath, bigSlider.Image);
            _db.BigSliders.Remove(bigSlider);
            await _db.SaveChangesAsync();

            return(RedirectToAction(nameof(Index)));
        }
Example #5
0
        public async Task <IActionResult> DeletePost(int?id)
        {
            if (id == null)
            {
                return(Content("Id tapilmadiq"));
            }
            Brand brand = await _db.Brands.FindAsync(id);

            if (brand == null)
            {
                return(NotFound());
            }

            Assistant.DeleteFromFolder(_env.WebRootPath, brand.Path);

            _db.Brands.Remove(brand);
            await _db.SaveChangesAsync();

            return(RedirectToAction(nameof(Index)));
        }
        public async Task <IActionResult> Update(int?id, WeekCategory weekCategory)
        {
            if (id == null)
            {
                return(NotFound());
            }
            WeekCategory dbweekCategory = await _db.WeekCategories.FindAsync(id);

            if (weekCategory == null)
            {
                return(NotFound());
            }

            if (weekCategory.Photo == null)
            {
                ModelState.AddModelError("Photo", "You can choose which of Image");
                return(View());
            }

            if (!weekCategory.Photo.IsImage())
            {
                ModelState.AddModelError("Photo", "You can choose only Image Format");
                return(View());
            }

            if (!weekCategory.Photo.CheckSize(2))
            {
                ModelState.AddModelError("Photo", "You can choosen only small at 2mb");
                return(View());
            }

            string filename = await weekCategory.Photo.CopyImage(_env.WebRootPath, "banner");

            Assistant.DeleteFromFolder(_env.WebRootPath, dbweekCategory.Image);
            dbweekCategory.Image = filename;

            await _db.SaveChangesAsync();

            return(RedirectToAction(nameof(Index)));
        }