Пример #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> Subscribe(string email)
        {
            if (ModelState.IsValid)
            {
                var subscribe = new Subscribe
                {
                    Email = email
                };

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

                return(Json(new
                {
                    error = false,
                    message = "Abonə oldunuz"
                }));
            }
            return(Json(new
            {
                error = true,
                message = "Xəta baş verdi"
            }));
        }
Пример #5
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));
        }
Пример #6
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));
        }