Пример #1
0
        public async Task <IActionResult> Create([Bind("Id,Name,Surname,Phone,Phone2,Email,Address,Agency,Description,FacebookLink,InstagramLink,TwitterLink,ImagePath,CreatedDate")] Agent agent, IFormFile image)
        {
            if (ModelState.IsValid)
            {
                var    ext      = Path.GetExtension(image.FileName);
                string purePath = $"agent-{Guid.NewGuid()}{ext}";

                string fileName = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot", "uploads", purePath);

                using (var fs = new FileStream(fileName, FileMode.CreateNew, FileAccess.Write))
                {
                    image.CopyTo(fs);
                }


                agent.ImagePath = purePath;


                _context.Add(agent);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(agent));
        }
Пример #2
0
        public async Task <IActionResult> Create([Bind("Id,Email")] Subscribe subscribe)
        {
            if (ModelState.IsValid)
            {
                _context.Add(subscribe);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(subscribe));
        }
Пример #3
0
        public async Task <IActionResult> Create([Bind("Id,Name")] City city)
        {
            if (ModelState.IsValid)
            {
                _context.Add(city);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(city));
        }
Пример #4
0
        public async Task <IActionResult> DeleteUser(int id)
        {
            var user = await db.Users.FindAsync(id);

            db.Users.Remove(user);
            await db.SaveChangesAsync();

            return(Json(new
            {
                error = false,
                message = "ok"
            }));
        }
Пример #5
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,AppTitle,LogoPath,FooterLogoPath,Description,Address,Phone,Phone2,WorkOurs,Email,FacebookLink,InstagramLink,TwitterLink,HomePhoto1,HomePhoto2,HomePhoto3,AnnounceAdvantages,AgentAdvantages,CategoryPhoto1,CategoryPhoto2,CategoryPhoto3,CategoryPhoto4")] AppInfo appInfo)
        {
            if (id != appInfo.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(appInfo);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!AppInfoExists(appInfo.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(View());
            }
            return(View(appInfo));
        }
Пример #6
0
        public async Task <IActionResult> CommentAdd(int homeId, string message)
        {
            if (ModelState.IsValid)
            {
                var userId = User.Claims.FirstOrDefault(c => c.Type == ClaimTypes.NameIdentifier)?.Value;

                if (userId == null)
                {
                    return(Json(new
                    {
                        error = true,
                        message = "Daxil Olun"
                    }));
                }

                var owner = db.Users.FirstOrDefault(a => a.Id == int.Parse(userId));

                var home = db.Homes.FirstOrDefault(h => h.Id == homeId);

                home.Comments = new List <Comment>();

                var comment = new Comment
                {
                    Message = message,
                    OwnerId = int.Parse(userId),
                    HomeId  = homeId
                };

                home.Comments.Add(comment);

                db.Update(home);
                await db.SaveChangesAsync();



                var date = comment.CreatedDate.ToString("dddd, dd MMMM yyyy");

                return(Json(new
                {
                    error = false,
                    message = "Yorum elava olundu",
                    ownerName = owner.UserName,
                    date = date,
                    commentMesage = message
                }));
            }

            return(Json(new
            {
                error = true,
                message = "Xəta baş verdi"
            }));
        }
Пример #7
0
        public async Task <IActionResult> Create(Home home)
        {
            if (ModelState.IsValid)
            {
                home.Images = new List <HomeImage>();

                if (home.file == null)
                {
                    return(View(home));
                }

                for (int i = 0; i < home.file.Length; i++)
                {
                    //tttt-tttt-ttttt.js
                    string ext      = Path.GetExtension(home.file[i].FileName);
                    string purePath = $"home-{Guid.NewGuid()}{ext}";

                    string fileName = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot", "uploads", purePath);


                    using (var fs = new FileStream(fileName, FileMode.CreateNew, FileAccess.Write))
                    {
                        home.file[i].CopyTo(fs);
                    }

                    home.Images.Add(new HomeImage
                    {
                        Path   = purePath,
                        IsMain = i == home.fileSelectedIndex
                    });
                }


                #region edits
                if (home.Period == "All")
                {
                    home.Period = null;
                }
                if (home.AgentId == 0)
                {
                    home.AgentId = null;
                }
                if (home.CityId == 0)
                {
                    home.CityId = null;
                }
                if (home.MetroId == 0)
                {
                    home.MetroId = null;
                }
                if (home.AnnounceType == "Sale")
                {
                    home.Period = null;
                }
                if (home.BakuDistrictId == 0)
                {
                    home.BakuDistrictId = null;
                }
                if (home.NMRDistrictId == 0)
                {
                    home.NMRDistrictId = null;
                }

                if (home.CityId != 6 && home.CityId != 1)
                {
                    home.BakuDistrictId = null;
                    home.NMRDistrictId  = null;
                }
                if (home.CityId != 1)
                {
                    home.MetroId = null;
                }
                if (home.CategoryId != 6)
                {
                    home.Floor = null;
                }
                #endregion

                var ownerId = User.Claims.FirstOrDefault(c => c.Type == ClaimTypes.NameIdentifier)?.Value;

                home.OwnerId = int.Parse(ownerId);


                _context.Add(home);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["AgentId"]    = new SelectList(_context.Agents, "Id", "Name", home.AgentId);
            ViewData["CategoryId"] = new SelectList(_context.Categories, "Id", "Name", home.CategoryId);
            ViewData["CityId"]     = new SelectList(_context.Cities, "Id", "Name", home.CityId);
            ViewData["MetroId"]    = new SelectList(_context.Metros, "Id", "Name", home.MetroId);



            ViewData["BakuDistrictId"] = new SelectList(_context.BakuDistricts, "Id", "Name", home.BakuDistrictId);
            ViewData["NMRDistrictId"]  = new SelectList(_context.NMRDistricts, "Id", "Name", home.NMRDistrictId);


            return(View(home));
        }
Пример #8
0
        public async Task <IActionResult> RegistrAgent(string agentName, string agentSurname, string agentPhone, string agentPhone2,
                                                       string agentAdress, string facebookLink, string instagramLink, string twitterLink, string agentDescription, IFormFile image,
                                                       string agnetUsername, string agentEmail, string agentPassword)
        {
            if (ModelState.IsValid)
            {
                var tryuserId = User.Claims.FirstOrDefault(c => c.Type == ClaimTypes.NameIdentifier)?.Value;

                if (tryuserId != null)
                {
                    TempData["message"] = $"Siz artıq qeydiyyatdan keçmisinin";
                }

                #region Create User
                if (db.Users.Any(a => a.NormalizedUserName == agnetUsername.ToUpper()))
                {
                    TempData["message"] = $"{agnetUsername} istifadəçi adı artıq mövcuddur. Zəhmət olmasa fərqli bir ad yazın";
                    return(RedirectToAction(nameof(Login)));
                }
                if (db.Users.Any(a => a.NormalizedEmail == agentEmail.ToUpper()))
                {
                    TempData["message"] = $"{agentEmail}Bu E-mail artıq mövcuddur. Zəhmət olmasa fərqli bir email yazın";
                    return(RedirectToAction(nameof(Login)));
                }

                var user = new AppUser
                {
                    UserName = agnetUsername,
                    Email    = agentEmail
                };

                string role = "Agent";

                if (userManager.CreateAsync(user, agentPassword).Result.Succeeded)
                {
                    userManager.AddToRoleAsync(user, role).Wait();
                }

                ///////////////////////////////////////////////////////////

                #endregion

                var userNew = await userManager.FindByNameAsync(agnetUsername);

                #region Add Agent

                var agent = new Agent
                {
                    Name          = agentName,
                    Surname       = agentSurname,
                    Email         = userNew.Email,
                    Phone         = agentPhone,
                    Phone2        = agentPhone2,
                    Address       = agentAdress,
                    FacebookLink  = facebookLink,
                    InstagramLink = instagramLink,
                    TwitterLink   = twitterLink,
                    Description   = agentDescription,
                    OwnerId       = userNew.Id
                };

                var    ext      = Path.GetExtension(image.FileName);
                string purePath = $"agent-{Guid.NewGuid()}{ext}";

                string fileName = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot", "uploads", purePath);

                using (var fs = new FileStream(fileName, FileMode.CreateNew, FileAccess.Write))
                {
                    image.CopyTo(fs);
                }


                agent.ImagePath = purePath;


                db.Agents.Add(agent);
                await db.SaveChangesAsync();

                #endregion


                #region Sign in


                if (userNew == null)
                {
                    TempData["message"] = "İstifadəçi adı və ya şifrə səhvdir";
                    return(RedirectToAction(nameof(Login)));
                }

                //var roleNew =await db.UserRoles.FirstOrDefaultAsync(c => c.UserId == userNew.Id);

                var agents = await userManager.GetUsersInRoleAsync("Agent");


                if (agents.Contains(userNew))
                {
                    string redirectLink = Request.Query["ReturnUrl"];

                    if (!string.IsNullOrWhiteSpace(redirectLink))
                    {
                        return(Redirect(redirectLink));
                    }

                    var signInResult = await signInManager.PasswordSignInAsync(userNew, agentPassword, true, true);

                    if (!signInResult.Succeeded)
                    {
                        TempData["message"] = "İstifadəçi adı və ya şifrə səhvdir";
                        return(RedirectToAction(nameof(Login)));
                    }
                }
                #endregion

                return(RedirectToAction("AddAnnounce", "client"));

                //return RedirectToAction(nameof(Index));
            }
            return(RedirectToAction(nameof(Login)));
        }
Пример #9
0
        public async Task <IActionResult> AddAnnounce(Home home)
        {
            if (ModelState.IsValid)
            {
                var userId = User.Claims.FirstOrDefault(c => c.Type == ClaimTypes.NameIdentifier)?.Value;

                //var user=await userManager.FindByIdAsync(userId);

                //var clients= await userManager.GetUsersInRoleAsync("Client");

                //if (clients.Contains(user))
                //{
                //    if (home.SellerName==null || home.SellerName=="")
                //    {
                //        ViewBag.NullValue = "Satıcı adı qeyd olunmalıdır";
                //        return View(home);
                //    }
                //    if (home.Phone == null || home.Phone == "" )
                //    {
                //        ViewBag.NullValue = "Telefon nömrəsi qeyd olunmalıdır";
                //        return View(home);
                //    }
                //}

                home.Images = new List <HomeImage>();

                if (home.file == null)
                {
                    return(View(home));
                }


                for (int i = 0; i < home.file.Length; i++)
                {
                    //tttt-tttt-ttttt.js
                    string ext      = Path.GetExtension(home.file[i].FileName);
                    string purePath = $"home-{Guid.NewGuid()}{ext}";

                    string fileName = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot", "uploads", purePath);


                    using (var fs = new FileStream(fileName, FileMode.CreateNew, FileAccess.Write))
                    {
                        home.file[i].CopyTo(fs);
                    }

                    home.Images.Add(new HomeImage
                    {
                        Path   = purePath,
                        IsMain = i == home.fileSelectedIndex
                    });
                }


                #region edits
                if (home.Period == "All")
                {
                    home.Period = null;
                }
                if (home.CityId == 0)
                {
                    home.CityId = null;
                }
                if (home.MetroId == 0)
                {
                    home.MetroId = null;
                }
                if (home.AnnounceType == "Sale")
                {
                    home.Period = null;
                }
                if (home.BakuDistrictId == 0)
                {
                    home.BakuDistrictId = null;
                }
                if (home.NMRDistrictId == 0)
                {
                    home.NMRDistrictId = null;
                }

                if (home.CityId != 6 && home.CityId != 1)
                {
                    home.BakuDistrictId = null;
                    home.NMRDistrictId  = null;
                }
                if (home.CityId != 1)
                {
                    home.MetroId = null;
                }
                if (home.CategoryId != 6)
                {
                    home.Floor = null;
                }
                if (home.CategoryId == 3)
                {
                    home.Area = null;
                }
                #endregion


                var intUserId = int.Parse(userId);

                home.OwnerId = intUserId;

                if (db.Agents.Any(a => a.OwnerId == intUserId))
                {
                    home.AgentId = db.Agents.FirstOrDefault(a => a.OwnerId == intUserId).Id;
                }
                else
                {
                    home.AgentId = null;
                }


                db.Add(home);
                await db.SaveChangesAsync();

                return(RedirectToAction(nameof(MyAnnounces)));
            }
            ViewData["AgentId"]    = new SelectList(db.Agents, "Id", "Name", home.AgentId);
            ViewData["CategoryId"] = new SelectList(db.Categories, "Id", "Name", home.CategoryId);
            ViewData["CityId"]     = new SelectList(db.Cities, "Id", "Name", home.CityId);
            ViewData["MetroId"]    = new SelectList(db.Metros, "Id", "Name", home.MetroId);


            ViewData["BakuDistrictId"] = new SelectList(db.BakuDistricts, "Id", "Name", home.BakuDistrictId);
            ViewData["NMRDistrictId"]  = new SelectList(db.NMRDistricts, "Id", "Name", home.NMRDistrictId);


            return(View(home));
        }