예제 #1
0
        public async Task <IActionResult> Elaniengelle(int?Id, Announcement announcement)
        {
            if (Id == null)
            {
                return(NotFound());
            }

            Announcement announcementFromDb = _context.Announcements.Where(announce => announce.IsActive == false && announce.IsDeleted == false && announce.IsBan == false).FirstOrDefault(ann => ann.Id == Id);

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

            announcementFromDb.IsActive  = false;
            announcementFromDb.IsDeleted = false;
            announcementFromDb.IsBan     = true;

            await _context.SaveChangesAsync();

            #region Sending Email Announcement Banned Message
            string messageSubject = "Elan təsdiq olunmadı";
            string messageBody    = $"<table style='width:100%;background-color:#AD0028;padding:50px'><thead style ='width:100%;display:flex;justify-content:center;'><tr style ='width:100%;display:flex;justify-content:center;'><th style ='width:100%;color:#F9F9F9;font-family:Roboto, sans-serif;font-weight:400;font-size:50px'>Kirayemlak.az</th></tr><thead><tbody><tr><td style ='padding:30px 0px;color:white;font-family:Roboto Condensed, sans-serif;font-size:20px;text-align:center;'>Hörmətli istifadəçi, dərc etdiyiniz elan qaydalara uyğun olmadığına görə təsdiq olunmadı. Zəhmət olmasa, 'Qaydalar' bölməsində təsvir edilmiş qaydaları yenidən nəzərdən keçirin.</td></tr><tr><td style ='font-family:Roboto Condensed, sans-serif;text-align:center;'><a href='http://kirayemlak.az/Qaydalar' style ='text-decoration:none;padding:10px 30px;border-radius:3px;background-color:#F9F9F9;color:#292C34;font-weight:lighter;font-size:20px;cursor:pointer;'>Qaydalar</a></td></tr></tbody></table>";
            await UtilityRealEstate.SendMessage(_configuration, announcementFromDb.CustomUser.Email, messageSubject, messageBody);

            #endregion

            TempData["AnnouncementBanned"] = true;

            return(RedirectToAction("Tesdiqedilmemish", "Elanlar"));
        }
        public async Task <IActionResult> Index()
        {
            ViewBag.Home      = "Home";
            ViewBag.Durations = _context.Durations;
            ViewBag.Estates   = _context.Estates;
            ViewBag.Rooms     = _context.Rooms;
            ViewBag.Cities    = _context.Cities;

            //Calling reusable method
            bool succeeded = await UtilityRealEstate.DbInitializer(_userManager, _roleManager);

            if (succeeded == true)
            {
                await UtilityRealEstate.DbInitializer(_userManager, _roleManager);
            }
            else
            {
                return(RedirectToAction("Index", "Xeta"));
            }

            HomeViewModel homeViewModel = new HomeViewModel
            {
                VIP_Announcements       = _context.Announcements.Where(ann => ann.IsActive == true).OrderByDescending(announcement => announcement.PublishDate).Where(announce => announce.IsVIP == true),
                RecentAnnouncements     = _context.Announcements.Where(ann => ann.IsActive == true).OrderByDescending(announcement => announcement.PublishDate),
                MostViewedAnnouncements = _context.Announcements.Where(ann => ann.IsActive == true).OrderByDescending(announcement => announcement.PublishDate).OrderByDescending(announce => announce.ViewCount)
            };

            ViewBag.Cookie = Request.Cookies["***FavouriteAnnouncement***"];

            return(View(homeViewModel));
        }
예제 #3
0
        public async Task <IActionResult> Shifreniunutdum(ForgotPasswordViewModel forgotPasswordViewModel)
        {
            if (!ModelState.IsValid)
            {
                return(View(forgotPasswordViewModel));
            }

            CustomUser customUserFromDb = await _userManager.FindByEmailAsync(forgotPasswordViewModel.Email);

            if (customUserFromDb == null)
            {
                ModelState.AddModelError("", "Bu email veb portalda qeydiyyatdan keçirilməyib.");
                return(View(forgotPasswordViewModel));
            }

            string passwordResetToken = await _userManager.GeneratePasswordResetTokenAsync(customUserFromDb);

            #region Sending Email Account Restoration Message
            string messageSubject = "Hesabın bərpası";
            string messageBody    = $"<table style='width:100%;background-color:#AD0028;padding:50px'><thead style ='width:100%;display:flex;justify-content:center;'><tr style ='width:100%;display:flex;justify-content:center;'><th style ='width:100%;color:#F9F9F9;font-family:Roboto, sans-serif;font-weight:400;font-size:50px'>Kirayemlak.az</th></tr><thead><tbody><tr><td style ='padding:30px 0px;color:white;font-family:Roboto Condensed, sans-serif;font-size:20px;text-align:center;'>Hörmətli istifadəçi, hesabınızın bərpası üçün aşağıdakı 'Hesabını bərpa et' düyməsinə tıklayın.</td></tr><tr><td style ='font-family:Roboto Condensed, sans-serif;text-align:center;'><a href='http://kirayemlak.az/Hesab/Shifrenideyish?userId={customUserFromDb.Id}&passwordResetToken={passwordResetToken}' style ='text-decoration:none;padding:10px 30px;border-radius:3px;background-color:#F9F9F9;color:#292C34;font-weight:lighter;font-size:20px;cursor:pointer;'>Hesabını bərpa et</a></td></tr></tbody></table>";
            await UtilityRealEstate.SendMessage(_configuration, forgotPasswordViewModel.Email, messageSubject, messageBody, customUserFromDb, customUserFromDb, passwordResetToken, passwordResetToken);

            #endregion

            TempData["ForgotPassword"] = true;

            return(View());
        }
예제 #4
0
        public async Task <IActionResult> Girish()
        {
            //Calling reusable method
            bool succeeded = await UtilityRealEstate.DbInitializer(_userManager, _roleManager);

            if (succeeded == true)
            {
                await UtilityRealEstate.DbInitializer(_userManager, _roleManager);
            }
            else
            {
                return(RedirectToAction("Index", "Xeta"));
            }

            if (User.Identity.IsAuthenticated)
            {
                return(RedirectToAction("Index", "Anasehife"));
            }

            return(View());
        }
예제 #5
0
        public async Task <IActionResult> Elanitesdiqet(int?Id, Announcement announcement)
        {
            if (Id == null)
            {
                return(NotFound());
            }

            ViewBag.AnnouncementId = Id;

            Announcement announcementFromDb = _context.Announcements.Where(announce => announce.IsActive == false && announce.IsDeleted == false && announce.IsBan == false).FirstOrDefault(ann => ann.Id == Id);

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

            ViewBag.IsVIP      = announcementFromDb.IsVIP;
            ViewBag.EstateName = announcementFromDb.Estate.EstateName;
            ViewBag.CityName   = announcementFromDb.City.CityName;

            if (announcement.EstateId == 1 || announcement.EstateId == 2)
            {
                ViewBag.Room = announcementFromDb.Room.RoomType;
            }

            ViewBag.Photos      = announcementFromDb.AnnouncementPhotos.ToList();
            ViewBag.Area        = announcementFromDb.Area;
            ViewBag.AreaForView = announcementFromDb.AreaForView;
            ViewBag.Duration    = announcementFromDb.Duration.DurationType;
            ViewBag.Price       = announcementFromDb.Price;
            ViewBag.Details     = announcementFromDb.Details;

            if (!ModelState.IsValid)
            {
                ViewBag.AnnouncementId = Id;
                ViewBag.IsVIP          = announcementFromDb.IsVIP;
                ViewBag.EstateName     = announcementFromDb.Estate.EstateName;
                ViewBag.CityName       = announcementFromDb.City.CityName;

                if (announcement.EstateId == 1 || announcement.EstateId == 2)
                {
                    ViewBag.Room = announcementFromDb.Room.RoomType;
                }

                ViewBag.Photos      = announcementFromDb.AnnouncementPhotos.ToList();
                ViewBag.Area        = announcementFromDb.Area;
                ViewBag.AreaForView = announcementFromDb.AreaForView;
                ViewBag.Duration    = announcementFromDb.Duration.DurationType;
                ViewBag.Price       = announcementFromDb.Price;
                ViewBag.Details     = announcementFromDb.Details;

                return(View("Elan", announcement));
            }

            announcementFromDb.Area        = announcement.Area;
            announcementFromDb.AreaForView = announcement.AreaForView;
            announcementFromDb.Price       = announcement.Price;
            announcementFromDb.Details     = announcement.Details;
            announcementFromDb.IsActive    = true;
            announcementFromDb.IsDeleted   = false;
            announcementFromDb.IsBan       = false;

            await _context.SaveChangesAsync();

            #region Sending Email AnnouncementConfirmed Message
            string messageSubject = "Elan təsdiq olundu";
            string messageBody    = $"<table style='width:100%;background-color:#292C34;padding:50px'><thead style ='width:100%;display:flex;justify-content:center;'><tr style ='width:100%;display:flex;justify-content:center;'><th style ='width:100%;color:#F9F9F9;font-family:Roboto, sans-serif;font-weight:400;font-size:50px'>Kirayemlak.az</th></tr><thead><tbody><tr><td style ='padding:30px 0px;color:#888888;font-family:Roboto Condensed, sans-serif;font-size:20px;text-align:center;'>Hörmətli istifadəçi, dərc etdiyiniz elan təsdiqləndi. Hesabınıza daxil olaraq elana baxa bilərsiniz.</td></tr><tr><td style ='font-family:Roboto Condensed, sans-serif;text-align:center;'><a href='http://kirayemlak.az/Hesab/Girish' style ='text-decoration:none;padding:10px 30px;border-radius:3px;background-color:#F9F9F9;color:#292C34;font-weight:lighter;font-size:20px;cursor:pointer;'>Daxil ol</a></td></tr></tbody></table>";
            await UtilityRealEstate.SendMessage(_configuration, announcementFromDb.CustomUser.Email, messageSubject, messageBody);

            #endregion

            TempData["AnnouncementConfirmed"] = true;

            return(RedirectToAction("Aktiv", "Elanlar"));
        }
예제 #6
0
        public async Task <IActionResult> Qeydiyyat(RegisterViewModel registerViewModel)
        {
            if (User.Identity.IsAuthenticated)
            {
                return(RedirectToAction("Menimhesabim", "Hesab"));
            }

            MobileOperator mobileOperatorFromDb = _context.MobileOperators.FirstOrDefault(mo => mo.Id == registerViewModel.MobileOperatorId);

            if (!ModelState.IsValid)
            {
                ViewBag.MobileOperators = _context.MobileOperators;
                return(View(registerViewModel));
            }

            if (registerViewModel.UploadFile == null)
            {
                ViewBag.MobileOperators = _context.MobileOperators;
                ModelState.AddModelError("", "Zəhmət olmasa, şəkil yükləyin");
                return(View(registerViewModel));
            }

            CustomUser customUser = new CustomUser
            {
                FirstName        = registerViewModel.FirstName.Trim(),
                UserName         = registerViewModel.Email.Trim(),
                Email            = registerViewModel.Email.Trim(),
                MobileOperatorId = registerViewModel.MobileOperatorId,
                PhoneNumber      = mobileOperatorFromDb.MobileOperatorCode + registerViewModel.PhoneNumber.Trim()
            };

            if (registerViewModel.LastName != null)
            {
                customUser.LastName = registerViewModel.LastName.Trim();
            }

            IdentityResult result = await _userManager.CreateAsync(customUser, registerViewModel.Password);

            if (!result.Succeeded)
            {
                ModelState.AddModelError("", "Bu email artıq qeydiyyatdan keçirilib və ya şifrə tələblərə uyğun deyil.");
                ViewBag.MobileOperators = _context.MobileOperators;
                return(View(registerViewModel));
            }

            if (registerViewModel.UploadFile.ContentType.Contains("image/jpg") || registerViewModel.UploadFile.ContentType.Contains("image/jpeg"))
            {
                if (registerViewModel.UploadFile.Length > (2 * 1024 * 1024))
                {
                    await _userManager.DeleteAsync(customUser);

                    await _context.SaveChangesAsync();

                    ViewBag.MobileOperators = _context.MobileOperators;
                    ModelState.AddModelError("", "Şəklin həcmi 2MB'dan çox ola bilməz.");
                    return(View(registerViewModel));
                }

                string folderPath = Path.Combine(_env.WebRootPath, "MainPageFiles", "images", "users");
                fileName = Guid.NewGuid().ToString() + "_istifadechi_" + registerViewModel.UploadFile.FileName;
                string filePath = Path.Combine(folderPath, fileName);

                using (FileStream fileStream = new FileStream(filePath, FileMode.Create))
                {
                    await registerViewModel.UploadFile.CopyToAsync(fileStream);
                }
                customUser.ProfilePictureURL = fileName;
            }
            else
            {
                await _userManager.DeleteAsync(customUser);

                await _context.SaveChangesAsync();

                ViewBag.MobileOperators = _context.MobileOperators;
                ModelState.AddModelError("", "Zəhmət olmasa, tələb olunan formatda şəkil yükləyin");
                return(View(registerViewModel));
            }

            await _userManager.AddToRoleAsync(customUser, "İstifadəçi");

            await _context.SaveChangesAsync();

            string emailConfirmationToken = await _userManager.GenerateEmailConfirmationTokenAsync(customUser);

            #region Sending Email Confirmation Message
            string messageSubject = "Hesabın təsdiqlənməsi";
            string messageBody    = $"<table style='width:100%;background-color:#292C34;padding:50px'><thead style ='width:100%;display:flex;justify-content:center;'><tr style ='width:100%;display:flex;justify-content:center;'><th style ='width:100%;color:#F9F9F9;font-family:Roboto, sans-serif;font-weight:400;font-size:50px'>Kirayemlak.az</th></tr><thead><tbody><tr><td style ='padding:30px 0px;color:#888888;font-family:Roboto Condensed, sans-serif;font-size:20px;text-align:center;'>Hörmətli istifadəçi, qeydiyyatdan uğurla keçdiniz. Hesabınızı təsdiqləmək üçün aşağıdakı 'Hesabını təsdiqlə' düyməsinə tıklayın.</td></tr><tr><td style ='font-family:Roboto Condensed, sans-serif;text-align:center;'><a href='http://kirayemlak.az/Hesab/Tesdiqetme?userId={customUser.Id}&emailConfirmationToken={emailConfirmationToken}' style ='text-decoration:none;padding:10px 30px;border-radius:3px;background-color:#F9F9F9;color:#292C34;font-weight:lighter;font-size:20px;cursor:pointer;'>Hesabını təsdiqlə</a></td></tr></tbody></table>";
            await UtilityRealEstate.SendMessage(_configuration, registerViewModel.Email, messageSubject, messageBody, customUser, customUser, emailConfirmationToken);

            #endregion

            ViewBag.MobileOperators       = _context.MobileOperators;
            TempData["AccountRegistered"] = true;
            return(View());
        }
예제 #7
0
        public async Task <IActionResult> Istifadechininmelumatlari(AccountDetailsViewModel accountDetailsViewModel)
        {
            string     activeUserName   = User.Identity.Name;
            CustomUser customUserFromDb = await _userManager.FindByNameAsync(activeUserName);

            if (customUserFromDb == null)
            {
                return(View("Views/Xeta/Index.cshtml"));
            }

            MobileOperator mobileOperatorFromDb = _context.MobileOperators.FirstOrDefault(mo => mo.Id == accountDetailsViewModel.MobileOperatorId);

            if (!ModelState.IsValid)
            {
                ViewBag.FirstName = customUserFromDb.FirstName;
                ViewBag.LastName  = customUserFromDb.LastName;
                ViewBag.Email     = customUserFromDb.Email;
                ViewBag.SelectedMobileOperatorId = customUserFromDb.MobileOperatorId;
                ViewBag.PhoneNumber     = customUserFromDb.PhoneNumber.Substring(6, 7);
                ViewBag.MobileOperators = _context.MobileOperators;
                return(View(accountDetailsViewModel));
            }

            string customUserFromDbOldEmail = customUserFromDb.Email;

            customUserFromDb.FirstName        = accountDetailsViewModel.FirstName.Trim();
            customUserFromDb.LastName         = accountDetailsViewModel.LastName.Trim();
            customUserFromDb.UserName         = accountDetailsViewModel.Email.Trim();
            customUserFromDb.Email            = accountDetailsViewModel.Email.Trim();
            customUserFromDb.MobileOperatorId = accountDetailsViewModel.MobileOperatorId;
            customUserFromDb.PhoneNumber      = mobileOperatorFromDb.MobileOperatorCode + accountDetailsViewModel.PhoneNumber.Trim();
            await _userManager.UpdateAsync(customUserFromDb);

            if (customUserFromDb.Email != customUserFromDbOldEmail)
            {
                customUserFromDb.EmailConfirmed = false;
            }
            await _userManager.UpdateAsync(customUserFromDb);

            if (accountDetailsViewModel.CurrentPassword != null && accountDetailsViewModel.NewPassword != null)
            {
                string replacedCurrentPassword = accountDetailsViewModel.CurrentPassword.Trim();
                string replacedNewPassword     = accountDetailsViewModel.NewPassword.Trim();

                IdentityResult result = await _userManager.ChangePasswordAsync(customUserFromDb, replacedCurrentPassword, replacedNewPassword);

                await _userManager.UpdateAsync(customUserFromDb);

                if (!result.Succeeded)
                {
                    ViewBag.FirstName = customUserFromDb.FirstName;
                    ViewBag.LastName  = customUserFromDb.LastName;
                    ViewBag.Email     = customUserFromDb.Email;
                    ViewBag.SelectedMobileOperatorId = customUserFromDb.MobileOperatorId;
                    ViewBag.PhoneNumber     = customUserFromDb.PhoneNumber.Substring(6, 7);
                    ViewBag.MobileOperators = _context.MobileOperators;
                    ViewBag.MobileOperators = _context.MobileOperators;
                    ModelState.AddModelError("CurrentPassword", "Hazırki şifrə yanlışdır və ya yeni şifrə tələblərə uyğun deyil.");
                    ModelState.AddModelError("NewPassword", "Hazırki şifrə yanlışdır və ya yeni şifrə tələblərə uyğun deyil.");
                    return(View(accountDetailsViewModel));
                }
            }

            if (accountDetailsViewModel.UploadFile != null)
            {
                if (accountDetailsViewModel.UploadFile.ContentType.Contains("image/jpg") || accountDetailsViewModel.UploadFile.ContentType.Contains("image/jpeg"))
                {
                    if (accountDetailsViewModel.UploadFile.Length > (2 * 1024 * 1024))
                    {
                        ViewBag.FirstName = customUserFromDb.FirstName;
                        ViewBag.LastName  = customUserFromDb.LastName;
                        ViewBag.Email     = customUserFromDb.Email;
                        ViewBag.SelectedMobileOperatorId = customUserFromDb.MobileOperatorId;
                        ViewBag.PhoneNumber     = customUserFromDb.PhoneNumber.Substring(6, 7);
                        ViewBag.MobileOperators = _context.MobileOperators;
                        ViewBag.MobileOperators = _context.MobileOperators;
                        ModelState.AddModelError("", "Şəklin həcmi 2MB'dan çox ola bilməz.");
                        return(View(accountDetailsViewModel));
                    }

                    string folderPath = Path.Combine(_env.WebRootPath, "MainPageFiles", "images", "users");
                    fileName = Guid.NewGuid().ToString() + "_istifadechi_" + accountDetailsViewModel.UploadFile.FileName;
                    string filePath = Path.Combine(folderPath, fileName);

                    //Deleting profile picture of the user from file system
                    string customUserFromDbFilePath = Path.Combine(_env.WebRootPath, "MainPageFiles", "images", "users", customUserFromDb.ProfilePictureURL);
                    if (System.IO.File.Exists(customUserFromDbFilePath))
                    {
                        try
                        {
                            System.IO.File.Delete(customUserFromDbFilePath);
                        }
                        catch
                        {
                            ModelState.AddModelError("UploadFile", "Xəta baş verdi");
                            return(View(accountDetailsViewModel));
                        }
                    }

                    using (FileStream fileStream = new FileStream(filePath, FileMode.Create))
                    {
                        await accountDetailsViewModel.UploadFile.CopyToAsync(fileStream);
                    }
                    customUserFromDb.ProfilePictureURL = fileName;
                    await _context.SaveChangesAsync();
                }
                else
                {
                    ViewBag.FirstName = customUserFromDb.FirstName;
                    ViewBag.LastName  = customUserFromDb.LastName;
                    ViewBag.Email     = customUserFromDb.Email;
                    ViewBag.SelectedMobileOperatorId = customUserFromDb.MobileOperatorId;
                    ViewBag.PhoneNumber     = customUserFromDb.PhoneNumber.Substring(6, 7);
                    ViewBag.MobileOperators = _context.MobileOperators;
                    ViewBag.MobileOperators = _context.MobileOperators;
                    ModelState.AddModelError("", "Zəhmət olmasa, tələb olunan formatda şəkil yükləyin");
                    return(View(accountDetailsViewModel));
                }
            }

            string emailConfirmationToken = await _userManager.GenerateEmailConfirmationTokenAsync(customUserFromDb);

            if (customUserFromDb.EmailConfirmed == false)
            {
                #region Sending Email Confirmation Message
                string messageSubject = "Hesabın(Yeni email ünvanı) təsdiqlənməsi";
                string messageBody    = $"<table style='width:100%;background-color:#292C34;padding:50px'><thead style ='width:100%;display:flex;justify-content:center;'><tr style ='width:100%;display:flex;justify-content:center;'><th style ='width:100%;color:#F9F9F9;font-family:Roboto, sans-serif;font-weight:400;font-size:50px'>Kirayeemlak.az</th></tr><thead><tbody><tr><td style ='padding:30px 0px;color:#888888;font-family:Roboto Condensed, sans-serif;font-size:20px;'>Hörmətli istifadəçi, yeni email ünvanınız uğurla qeydiyyatdan keçdi. Hesabınızı təsdiqləmək üçün aşağıdakı 'Hesabını təsdiqlə' düyməsinə tıklayın.</td></tr><tr><td style ='font-family:Roboto Condensed, sans-serif;text-align:center;'><a href='http://kirayemlak.az/Hesab/Tesdiqetme?userId={customUserFromDb.Id}&emailConfirmationToken={emailConfirmationToken}' style ='text-decoration:none;padding:10px 30px;border-radius:3px;background-color:#F9F9F9;color:#292C34;font-weight:lighter;font-size:20px;cursor:pointer;'>Hesabını təsdiqlə</a></td></tr></tbody></table>";
                await UtilityRealEstate.SendMessage(_configuration, accountDetailsViewModel.Email, messageSubject, messageBody, customUserFromDb, customUserFromDb, emailConfirmationToken);

                #endregion
            }

            TempData["AccountDetailsUpdated"] = true;

            ViewBag.FirstName = customUserFromDb.FirstName;
            ViewBag.LastName  = customUserFromDb.LastName;
            ViewBag.Email     = customUserFromDb.Email;
            ViewBag.SelectedMobileOperatorId = customUserFromDb.MobileOperatorId;
            ViewBag.PhoneNumber     = customUserFromDb.PhoneNumber.Substring(6, 7);
            ViewBag.MobileOperators = _context.MobileOperators;

            return(View());
        }