public async Task <IActionResult> DeletePost(int?id)
        {
            if (!User.Identity.IsAuthenticated)
            {
                return(RedirectToAction("Login", "Account"));
            }

            if (!User.IsInRole("Admin"))
            {
                return(RedirectToAction("Login", "Account"));
            }
            AferogluHistory category = await _context.AferogluHistory.FindAsync(id);

            string computerPhoto = Path.Combine(_env.WebRootPath, "images", category.PhotoUrl);

            if (System.IO.File.Exists(computerPhoto))
            {
                System.IO.File.Delete(computerPhoto);
            }

            _context.AferogluHistory.Remove(category);

            await _context.SaveChangesAsync();

            return(RedirectToAction(nameof(Index)));
        }
Beispiel #2
0
        public async Task <IActionResult> DeletePost(int?id)
        {
            if (!User.Identity.IsAuthenticated)
            {
                return(RedirectToAction("Login", "Account"));
            }

            if (!User.IsInRole("Admin"))
            {
                return(RedirectToAction("Login", "Account"));
            }
            Product category = await _context.Products.FindAsync(id);

            foreach (var p in category.Photos)
            {
                string computerPhoto = Path.Combine(_env.WebRootPath, "images", p.PhotoURL);

                if (System.IO.File.Exists(computerPhoto))
                {
                    System.IO.File.Delete(computerPhoto);
                }

                IEnumerable <ProductPhoto> productPhotos = _context.ProductPhotos.Where(p => p.ProductId == id);

                _context.ProductPhotos.RemoveRange(productPhotos);
            }


            _context.Products.Remove(category);

            await _context.SaveChangesAsync();

            return(RedirectToAction(nameof(Index)));
        }
Beispiel #3
0
        public async Task <IActionResult> EditPost(int id, CreateSliderVM slider)
        {
            if (!User.Identity.IsAuthenticated)
            {
                return(RedirectToAction("Login", "Account"));
            }

            if (!User.IsInRole("Admin"))
            {
                return(RedirectToAction("Login", "Account"));
            }
            if (!ModelState.IsValid)
            {
                ModelState.AddModelError("", "Xaiş olunur düzgün doldurun.");
                return(View(slider));
            }

            Slider newSlider = await _context.Sliders.FindAsync(id);

            if (newSlider == null)
            {
                return(View("Error"));
            }

            if (slider.Photo != null)
            {
                string computerPhoto = Path.Combine(_env.WebRootPath, "images", newSlider.PhotoUrl);

                if (System.IO.File.Exists(computerPhoto))
                {
                    System.IO.File.Delete(computerPhoto);
                }

                string fileName = await slider.Photo.SaveAsync(_env.WebRootPath);

                newSlider.PhotoUrl = fileName;
            }
            SliderLang azBlogLangFromDb = await _context.SliderLangs.FirstOrDefaultAsync(x => x.Lang.Code.ToLower() == "az" &&
                                                                                         x.SliderId == newSlider.Id);

            SliderLang ruBlogLangFromDb = await _context.SliderLangs.FirstOrDefaultAsync(x => x.Lang.Code.ToLower() == "ru" &&
                                                                                         x.SliderId == newSlider.Id);

            SliderLang enBlogLangFromDb = await _context.SliderLangs.FirstOrDefaultAsync(x => x.Lang.Code.ToLower() == "en" &&
                                                                                         x.SliderId == newSlider.Id);

            azBlogLangFromDb.Header      = slider.HeaderAZ;
            enBlogLangFromDb.Header      = slider.HeaderEN;
            ruBlogLangFromDb.Header      = slider.HeaderRU;
            azBlogLangFromDb.Description = slider.DescriptionAZ;
            azBlogLangFromDb.Description = slider.DescriptionEN;
            azBlogLangFromDb.Description = slider.DescriptionRU;

            await _context.SaveChangesAsync();

            return(RedirectToAction(nameof(Index)));
        }
Beispiel #4
0
        public async Task <IActionResult> EditPost(int id, CreateStaticDataVM staticData)
        {
            if (!User.Identity.IsAuthenticated)
            {
                return(RedirectToAction("Login", "Account"));
            }

            if (!User.IsInRole("Admin"))
            {
                return(RedirectToAction("Login", "Account"));
            }
            if (!ModelState.IsValid)
            {
                ModelState.AddModelError("", "Xaiş olunur düzgün doldurun.");
                return(View(staticData));
            }

            StaticData currentData = await _context.StaticData.FindAsync(id);

            if (currentData == null)
            {
                return(View("Error"));
            }

            StaticDataLang azBlogLangFromDb = await _context.StaticDataLangs.FirstOrDefaultAsync(x => x.Lang.Code.ToLower() == "az" &&
                                                                                                 x.StaticDataId == currentData.Id);

            StaticDataLang ruBlogLangFromDb = await _context.StaticDataLangs.FirstOrDefaultAsync(x => x.Lang.Code.ToLower() == "ru" &&
                                                                                                 x.StaticDataId == currentData.Id);

            StaticDataLang enBlogLangFromDb = await _context.StaticDataLangs.FirstOrDefaultAsync(x => x.Lang.Code.ToLower() == "en" &&
                                                                                                 x.StaticDataId == currentData.Id);

            currentData.EmailAdress       = staticData.EmailAdress;
            currentData.Facebook          = staticData.Facebook;
            currentData.Instagram         = staticData.Instagram;
            currentData.PhoneNumberOne    = staticData.PhoneNumberOne;
            currentData.PhoneNumberTwo    = staticData.PhoneNumberTwo;
            azBlogLangFromDb.Address      = staticData.AddressAZ;
            ruBlogLangFromDb.Address      = staticData.AddressRU;
            enBlogLangFromDb.Address      = staticData.AddressEN;
            currentData.Map               = staticData.Map;
            azBlogLangFromDb.WorkingHours = staticData.WorkingHoursAZ;
            ruBlogLangFromDb.WorkingHours = staticData.WorkingHoursRU;
            enBlogLangFromDb.WorkingHours = staticData.WorkingHoursEN;


            await _context.SaveChangesAsync();

            return(RedirectToAction(nameof(Details)));
        }
Beispiel #5
0
        public async Task <IActionResult> Edit(int id, CreateAboutVM about)
        {
            if (!User.Identity.IsAuthenticated)
            {
                return(RedirectToAction("Login", "Account"));
            }

            if (!User.IsInRole("Admin"))
            {
                return(RedirectToAction("Login", "Account"));
            }

            if (!ModelState.IsValid)
            {
                return(View(about));
            }

            var currentAbout = await _context.About.FirstOrDefaultAsync(p => p.Id == id);

            if (about.Photo != null)
            {
                string computerPhoto = Path.Combine(_env.WebRootPath, "images", currentAbout.PhotoURL);

                if (System.IO.File.Exists(computerPhoto))
                {
                    System.IO.File.Delete(computerPhoto);
                }

                string filename = await about.Photo.SaveAsync(_env.WebRootPath);

                currentAbout.PhotoURL = filename;
            }

            AboutLang azBlogLangFromDb = await _context.AboutLang.FirstOrDefaultAsync(x => x.Lang.Code.ToLower() == "az" &&
                                                                                      x.AboutId == currentAbout.Id);

            AboutLang ruBlogLangFromDb = await _context.AboutLang.FirstOrDefaultAsync(x => x.Lang.Code.ToLower() == "ru" &&
                                                                                      x.AboutId == currentAbout.Id);

            AboutLang enBlogLangFromDb = await _context.AboutLang.FirstOrDefaultAsync(x => x.Lang.Code.ToLower() == "en" &&
                                                                                      x.AboutId == currentAbout.Id);

            azBlogLangFromDb.Description = about.DescriptionAZ;
            enBlogLangFromDb.Description = about.DescriptionEN;
            ruBlogLangFromDb.Description = about.DescriptionRU;

            await _context.SaveChangesAsync();

            return(RedirectToAction("Index", "About"));
        }