Exemple #1
0
        public async Task <IActionResult> Edit(Slider slider)
        {
            if (!ModelState.IsValid)
            {
                return(View(slider));
            }

            var sliderDb = await _context.Sliders.FindAsync(slider.Id);

            if (slider.Photo != null)
            {
                try
                {
                    var newPhoto = await slider.Photo.SaveFileAsync(_env.WebRootPath, "images/service/");

                    IFormFileExtension.Delete(_env.WebRootPath, "images/service/", sliderDb.Image);
                    sliderDb.Image = newPhoto;
                }
                catch (Exception e)
                {
                    ModelState.AddModelError("", "Unexpected error happened while saving image. Please, try again.");
                    return(View(slider));
                }
            }

            sliderDb.Title    = slider.Title;
            sliderDb.Subtitle = slider.Subtitle;
            await _context.SaveChangesAsync();

            TempData["warning"] = "Slayder uğurla dəyişdirildi";
            return(RedirectToAction(nameof(Index)));
        }
Exemple #2
0
        public async Task <IActionResult> RemovePost(int?id)
        {
            if (id != null)
            {
                Team team = await _context.Teams.FirstOrDefaultAsync(t => t.Id == id);

                if (team != null)
                {
                    IFormFileExtension.Delete(_env.WebRootPath, "images/team", team.Image);
                    _context.Teams.Remove(team);
                    await _context.SaveChangesAsync();

                    return(RedirectToAction(nameof(Index)));
                }
            }
            return(NotFound());
        }
Exemple #3
0
        public async Task <IActionResult> DeleteService(int?id)
        {
            if (id != null)
            {
                var team = await _context.Teams.FirstOrDefaultAsync(s => s.Id == id);

                if (team != null)
                {
                    IFormFileExtension.Delete(_env.WebRootPath, "images/outsource/", team.Image);
                    _context.Teams.Remove(team);
                    await _context.SaveChangesAsync();

                    TempData["danger"] = "İşçi uğurla silindi";
                    return(RedirectToAction(nameof(Index)));
                }
            }

            return(NotFound());
        }
Exemple #4
0
        public async Task <IActionResult> DeleteProduct(int?id)
        {
            if (id != null)
            {
                var product = await _context.Products.FirstOrDefaultAsync(s => s.Id == id);

                if (product != null)
                {
                    IFormFileExtension.Delete(_env.WebRootPath, "images/shop/", product.Image);
                    _context.Products.Remove(product);
                    await _context.SaveChangesAsync();

                    TempData["danger"] = "Məhsul uğurla silindi";
                    return(RedirectToAction(nameof(Index)));
                }
            }

            return(NotFound());
        }
Exemple #5
0
        public async Task <IActionResult> DeleteSlider(int?id)
        {
            if (id != null)
            {
                var slider = await _context.Sliders.FirstOrDefaultAsync(s => s.Id == id);

                if (slider != null)
                {
                    IFormFileExtension.Delete(_env.WebRootPath, "images/service/", slider.Image);
                    _context.Sliders.Remove(slider);
                    await _context.SaveChangesAsync();

                    TempData["danger"] = "Slayder uğurla silindi";
                    return(RedirectToAction(nameof(Index)));
                }
            }

            return(NotFound());
        }
Exemple #6
0
        public async Task <IActionResult> Edit(ProductSpecificationViewModel product)
        {
            if (!ModelState.IsValid)
            {
                ViewBag.Categories = new SelectList(_context.CategoryProducts, "Id", "Name");
                return(View(product));
            }

            var productDb = await _context.Products.FindAsync(product.Id);

            if (product.Photo != null)
            {
                if (!product.Photo.IsImage())
                {
                    ModelState.AddModelError("Photo", "Şəkilin formatı jpg, jpeg, png, svg və ya gif formatında olmalıdır");
                    return(View(product));
                }
                try
                {
                    var newPhoto = await product.Photo.SaveFileAsync(_env.WebRootPath, "images/shop/");

                    IFormFileExtension.Delete(_env.WebRootPath, "images/shop/", productDb.Image);
                    productDb.Image = newPhoto;
                }
                catch (Exception e)
                {
                    ModelState.AddModelError("", "Unexpected error happened while saving image. Please, try again.");
                    return(View(product));
                }
            }

            productDb.Name              = product.Name;
            productDb.Description       = product.Description;
            productDb.CategoryProductId = product.CategoryProductId;
            productDb.Price             = product.Price;
            await _context.SaveChangesAsync();



            TempData["warning"] = "Məhsul uğurla dəyişdirildi";
            return(RedirectToAction(nameof(Index)));
        }
Exemple #7
0
        public async Task <IActionResult> Edit(Team team)
        {
            if (!ModelState.IsValid)
            {
                return(View(team));
            }



            var teamDb = await _context.Teams.FindAsync(team.Id);

            if (team.Photo != null)
            {
                if (!team.Photo.IsImage())
                {
                    ModelState.AddModelError("Photo", "Şəkilin formatı jpg, jpeg, png, svg və ya gif formatında olmalıdır");
                    return(View(team));
                }
                try
                {
                    var newPhoto = await team.Photo.SaveFileAsync(_env.WebRootPath, "images/outsource/");

                    IFormFileExtension.Delete(_env.WebRootPath, "images/outsource/", teamDb.Image);
                    teamDb.Image = newPhoto;
                }
                catch (Exception e)
                {
                    ModelState.AddModelError("", "Unexpected error happened while saving image. Please, try again.");
                    return(View(team));
                }
            }

            teamDb.Name     = team.Name;
            teamDb.Position = team.Position;
            await _context.SaveChangesAsync();

            TempData["warning"] = "İşçi uğurla dəyişdirildi";
            return(RedirectToAction(nameof(Index)));
        }
Exemple #8
0
        public async Task <IActionResult> Edit(Models.Service service)
        {
            if (!ModelState.IsValid)
            {
                return(View(service));
            }



            var serviceDb = await _context.Services.FindAsync(service.Id);

            if (service.Photo != null)
            {
                if (!service.Photo.IsImage())
                {
                    ModelState.AddModelError("Photo", "Şəkilin formatı jpg, jpeg, png, svg və ya gif formatında olmalıdır");
                    return(View(service));
                }
                try
                {
                    var newPhoto = await service.Photo.SaveFileAsync(_env.WebRootPath, "images/service/");

                    IFormFileExtension.Delete(_env.WebRootPath, "images/service/", serviceDb.Image);
                    serviceDb.Image = newPhoto;
                }
                catch (Exception e)
                {
                    ModelState.AddModelError("", "Unexpected error happened while saving image. Please, try again.");
                    return(View(service));
                }
            }

            serviceDb.Name        = service.Name;
            serviceDb.Description = service.Description;
            await _context.SaveChangesAsync();

            TempData["warning"] = "Xidmət uğurla dəyişdirildi";
            return(RedirectToAction(nameof(Index)));
        }
Exemple #9
0
        public async Task <IActionResult> Edit(News news)
        {
            if (!ModelState.IsValid)
            {
                return(View(news));
            }


            var newsDb = await _context.News.FindAsync(news.Id);

            if (news.Photo != null)
            {
                if (!news.Photo.IsImage())
                {
                    ModelState.AddModelError("Photo", "Şəkilin formatı jpg, jpeg, png, svg və ya gif formatında olmalıdır");
                    return(View(news));
                }
                try
                {
                    var newPhoto = await news.Photo.SaveFileAsync(_env.WebRootPath, "images/outsource/");

                    IFormFileExtension.Delete(_env.WebRootPath, "images/outsource/", newsDb.Image);
                    newsDb.Image = newPhoto;
                }
                catch (Exception e)
                {
                    ModelState.AddModelError("", "Unexpected error happened while saving image. Please, try again.");
                    return(View(news));
                }
            }

            newsDb.Name     = news.Name;
            newsDb.Subtitle = news.Subtitle;
            newsDb.Text     = news.Text;
            await _context.SaveChangesAsync();

            TempData["warning"] = "Xəbər uğurla dəyişdirildi";
            return(RedirectToAction(nameof(Index)));
        }
Exemple #10
0
        public async Task <IActionResult> Edit(Team team)
        {
            if (!ModelState.IsValid)
            {
                return(View(team));
            }

            var TeamDb = await _context.Teams.FindAsync(team.Id);

            if (team.Photo != null)
            {
                try
                {
                    var newPhoto = await team.Photo.SaveFileAsync(_env.WebRootPath, "images/team");

                    IFormFileExtension.Delete(_env.WebRootPath, "images/team", TeamDb.Image);
                    TeamDb.Image = newPhoto;
                }
                catch (Exception e)
                {
                    ModelState.AddModelError("", "Unexpected error happened while saving image. Please, try again.");
                    return(View(team));
                }
            }

            TeamDb.Title    = team.Title;
            TeamDb.SubTitle = team.SubTitle;
            TeamDb.Facebook = team.Facebook;
            TeamDb.Twitter  = team.Twitter;
            TeamDb.Google   = team.Google;
            TeamDb.Linkedin = team.Linkedin;
            TeamDb.Dribble  = team.Dribble;
            await _context.SaveChangesAsync();

            TempData["succes_message"] = "Team was updated successfuly";
            return(RedirectToAction(nameof(Index)));
        }