public async Task <IActionResult> EditProfile(UpdateProfileVM updateProfileVM)
        {
            if (!ModelState.IsValid)
            {
                ModelState.AddModelError("", "Zəhmət olmasa mobil operatorunuzu Daxil Edin");
                ViewBag.Operators = _context.Operators;
                return(View(updateProfileVM));
            }
            ApplicationUser applicationUser = await _userManager.FindByNameAsync(User.Identity.Name);

            applicationUser.Firstname   = updateProfileVM.applicationUser.Firstname;
            applicationUser.Lastname    = updateProfileVM.applicationUser.Lastname;
            applicationUser.UserName    = updateProfileVM.applicationUser.UserName;
            applicationUser.OperatorId  = updateProfileVM.OperatorId;
            applicationUser.PhoneNumber = updateProfileVM.applicationUser.PhoneNumber;

            if (updateProfileVM.applicationUser.Email != applicationUser.Email)
            {
                applicationUser.Email          = updateProfileVM.applicationUser.Email;
                applicationUser.EmailConfirmed = false;
                SmtpClient client = new SmtpClient("smtp.gmail.com", 587);
                client.UseDefaultCredentials = false;
                client.EnableSsl             = true;
                client.Credentials           = new NetworkCredential(_configuration["ConnectionsStrings:SmtpClientCredentialEmail"], _configuration["ConnectionsStrings:SmtpClientCredentialPassword"]);
                MailMessage message = new MailMessage("*****@*****.**", updateProfileVM.applicationUser.Email);
                message.IsBodyHtml = true;
                message.Subject    = "Hesabın təsdiqlənməsi";
                message.Body       = $"<a href='http://power123elec-001-site1.ctempurl.com/Account/EmailVerify?id={updateProfileVM.applicationUser.Id}'>Xahiş edirik hesabınızı təsdiqləyəsiniz</a>";
                await client.SendMailAsync(message);
            }
            if (updateProfileVM.Photo == null)
            {
                applicationUser.PhotoUrl = "noImage.png";
            }
            else if (updateProfileVM.Photo.ContentType.Contains("image/"))
            {
                string folderPath = Path.Combine(_env.WebRootPath, "userImages");
                string fileName   = Guid.NewGuid().ToString() + "_" + updateProfileVM.Photo.FileName;
                string filePath   = Path.Combine(folderPath, fileName);
                applicationUser.PhotoUrl = fileName;

                using (FileStream fileStream = new FileStream(filePath, FileMode.Create))
                {
                    await updateProfileVM.Photo.CopyToAsync(fileStream);
                }
            }
            if (updateProfileVM.NewPassword != null)
            {
                await _userManager.ChangePasswordAsync(applicationUser, updateProfileVM.СurrentPassword, updateProfileVM.NewPassword);
            }

            _context.SaveChanges();
            return(RedirectToAction("UserProfile", "Account"));
        }
Пример #2
0
        public IActionResult AdsDetails(int?id)
        {
            Announcement selectedAds = _context.Announcements.FirstOrDefault(a => a.Id == id);

            selectedAds.AnnouncementCount++;
            _context.SaveChanges();


            return(View(selectedAds));
        }