Esempio n. 1
0
        public async Task <IActionResult> ChangePassword(ChangePasswordVm changePassword)
        {
            if (User.Identity.IsAuthenticated && User.IsInRole("admin"))
            {
                AppUser currUser = await _userManager.GetUserAsync(User);

                if (currUser == null || !ModelState.IsValid)
                {
                    return(View(changePassword));
                }
                if (!await _userManager.CheckPasswordAsync(currUser, changePassword.OldPassword))
                {
                    ModelState.AddModelError("", "Köhnə şifrə düzgün deyil");
                    return(View(changePassword));
                }
                if (changePassword.Password != changePassword.ConfirmPassword)
                {
                    ModelState.AddModelError("", "Şifrəni düzgün təsdiqləyin");
                    return(View(changePassword));
                }
                var password = _configuration.GetValue <string>("Passwords:AdminPassword");
                await _userManager.ChangePasswordAsync(currUser, password, changePassword.ConfirmPassword);

                await _context.SaveChangesAsync();

                return(PartialView("PasswordChanged"));
            }
            return(RedirectToAction(nameof(Index)));
        }
Esempio n. 2
0
        public async Task <IActionResult> Update(WhyChooseUs whyChooseUs)
        {
            if (User.Identity.IsAuthenticated && User.IsInRole("admin"))
            {
                if (whyChooseUs == null || !ModelState.IsValid)
                {
                    return(NotFound());
                }
                if (whyChooseUs.Heading == string.Empty)
                {
                    ModelState.AddModelError("", "Başlıq boş olmamalıdır");
                    return(View(whyChooseUs));
                }
                if (whyChooseUs.Content == string.Empty)
                {
                    ModelState.AddModelError("", "Məzmun boş olmamalıdır");
                    return(View(whyChooseUs));
                }
                if (whyChooseUs.Icon == string.Empty)
                {
                    ModelState.AddModelError("", "Ikon boş olmamalıdır");
                    return(View(whyChooseUs));
                }
                WhyChooseUs fromDb = await _context.whyChooseUs.FindAsync(whyChooseUs.Id);

                fromDb.Heading = whyChooseUs.Heading;
                fromDb.Content = whyChooseUs.Content;
                fromDb.Icon    = whyChooseUs.Icon;
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(Redirect("/admin/account"));
        }
Esempio n. 3
0
        public async Task <IActionResult> Update(Contact contact)
        {
            if (User.Identity.IsAuthenticated && User.IsInRole("admin"))
            {
                if (!ModelState.IsValid || contact == null)
                {
                    return(NotFound());
                }
                if (contact.MainHeader == string.Empty)
                {
                    ModelState.AddModelError("", "Əsas Başlıq boş olmamalıdır");
                    return(View(contact));
                }
                if (contact.SmallHeader == string.Empty)
                {
                    ModelState.AddModelError("", "Kiçik Başlıq boş olmamalıdır");
                    return(View(contact));
                }
                if (contact.Adress == string.Empty)
                {
                    ModelState.AddModelError("", "Ünvan boş olmamalıdır");
                    return(View(contact));
                }
                if (contact.PhoneNumber == string.Empty)
                {
                    ModelState.AddModelError("", "Əlaqə nömrəsi boş olmamalıdır");
                    return(View(contact));
                }
                if (contact.Email == string.Empty)
                {
                    ModelState.AddModelError("", "Email boş olmamalıdır");
                    return(View(contact));
                }
                if (contact.Hours == string.Empty)
                {
                    ModelState.AddModelError("", "İş saatları boş olmamalıdır");
                    return(View(contact));
                }
                Contact contactFromDb = await _context.contact.FindAsync(contact.Id);

                if (contact.Image != null)
                {
                    if (!contact.Image.ContentType.Contains("image/"))
                    {
                        ModelState.AddModelError("", "Şəkilin formatı düzgün deyil");
                        return(View(contactFromDb));
                    }
                    RemovePhoto(_env.WebRootPath, contactFromDb.ImageUrl);
                    contactFromDb.ImageUrl = await contact.Image.SavePhotoAsync(_env.WebRootPath, "contactPhoto");
                }
                contactFromDb.MainHeader  = contact.MainHeader;
                contactFromDb.SmallHeader = contact.SmallHeader;
                contactFromDb.Adress      = contact.Adress;
                contactFromDb.PhoneNumber = contact.PhoneNumber;
                contactFromDb.Email       = contact.Email;
                contactFromDb.Hours       = contact.Hours;
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(Redirect("/admin/account"));
        }