public void Add_Post_Location(int ID_Post, int district, int ward, int street, string diachi, int province, int?project)
        {
            postlocation = new Post_Location();

            postlocation.ID_Post    = ID_Post;
            postlocation.Tinh_TP    = province;
            postlocation.Quan_Huyen = district;
            if (ward == 0)
            {
                postlocation.Phuong_Xa = null;
            }
            else
            {
                postlocation.Phuong_Xa = ward;
            }

            if (street == 0)
            {
                postlocation.Duong_Pho = null;
            }
            else
            {
                postlocation.Duong_Pho = street;
            }
            postlocation.DuAn   = project;
            postlocation.DiaChi = diachi;


            DataProvider.Ins.db.Post_Location.Add(postlocation);
            DataProvider.Ins.db.SaveChanges();
        }
        public async Task <IActionResult> Edit(int id, [Bind("ID_Post,ID_Account,PostTime,PostType,Tittle,Size,Project,Price,RealEstateType,Description,Status")] Post post, List <IFormFile> images, int district, int ward, int street
                                               , string diachi, bool alley, bool nearSchool, bool nearAirport, bool nearHospital, bool nearMarket, string descriptiondetail, int bathroom,
                                               int bedroom, int yard, int floor, int province)
        {
            if (id != post.ID_Post)
            {
                return(NotFound());
            }
            if (images.Count > 0 && images[0].Length > 0)
            {
                for (int i = 0; i < images.Count; i++)
                {
                    var file = images[i];

                    if (file != null && images[i].Length > 0)
                    {
                        string fileName          = Path.GetFileName(file.FileName);
                        string extensionFileName = Path.GetExtension(fileName);


                        fileName = fileName.Substring(0, fileName.Length - extensionFileName.Length) + "-" + DateTime.Now.ToString().Replace(" ", "").Replace(":", "").Replace("/", "") + extensionFileName;

                        var path = Path.Combine(Directory.GetCurrentDirectory(), @"wwwroot\images\posts", fileName);

                        using (var stream = new FileStream(path, FileMode.Create))
                        {
                            await file.CopyToAsync(stream);
                        }

                        Post_Image pstImg = new Post_Image();
                        pstImg.url       = fileName;
                        pstImg.AddedDate = DateTime.Now;
                        pstImg.ID_Post   = post.ID_Post;
                        _context.Post_Image.Add(pstImg);
                    }
                }
            }

            Post_Detail postdetail = _context.Post_Detail.Where(p => p.ID_Post == id).SingleOrDefault();

            postdetail.Alley        = alley;
            postdetail.Bathroom     = bathroom;
            postdetail.Bedroom      = bedroom;
            postdetail.Description  = descriptiondetail;
            postdetail.Floor        = floor;
            postdetail.NearAirport  = nearAirport;
            postdetail.NearHospital = nearHospital;
            postdetail.NearMarket   = nearMarket;
            postdetail.NearSchool   = nearSchool;
            postdetail.Yard         = yard;
            Post_Location post_Location = _context.Post_Location.Where(p => p.ID_Post == id).SingleOrDefault();

            post_Location.DiaChi = diachi;
            if (street == 0)
            {
                post_Location.Duong_Pho = null;
            }
            else
            {
                post_Location.Duong_Pho = street;
            }
            if (ward == 0)
            {
                post_Location.Phuong_Xa = null;
            }
            else
            {
                post_Location.Phuong_Xa = ward;
            }
            if (district == 0)
            {
                post_Location.Quan_Huyen = null;
            }
            else
            {
                post_Location.Quan_Huyen = district;
            }
            post_Location.Tinh_TP = province;
            post_Location.DuAn    = post.Project;
            var user = await _userManager.GetUserAsync(User);

            Post_Status post_Status = new Post_Status();

            post_Status.ID_Account   = user.Id;
            post_Status.ID_Post      = post.ID_Post;
            post_Status.Reason       = "Bài đăng được cập nhật. Xin đợi admin duyệt";
            post_Status.Status       = 5;
            post_Status.ModifiedDate = DateTime.Now;
            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(post);
                    _context.Update(postdetail);
                    _context.Update(post_Location);
                    _context.Post_Status.Add(post_Status);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!PostExists(post.ID_Post))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                //return View(post);
                return(RedirectToAction(nameof(Details), new { id = id }));
            }

            int Province = post.Post_Location.SingleOrDefault().Tinh_TPNavigation.id;
            int District = post.Post_Location.SingleOrDefault().Quan_HuyenNavigation.id;
            int Ward     = post.Post_Location.SingleOrDefault().Phuong_XaNavigation.id;
            int Street   = post.Post_Location.SingleOrDefault().Duong_PhoNavigation.id;

            ViewData["ID_Account"] = user.Id;
            string nameuser = "";

            if (user.IsAdmin == 1)
            {
                nameuser = "******" + _context.Admin.Where(p => p.Account_ID == user.Id).SingleOrDefault().FullName;
            }
            else
            {
                var cus = _context.Customer.Where(p => p.Account_ID == user.Id).SingleOrDefault();
                nameuser = cus.FirstName + " " + cus.LastName;
            }
            ViewData["Name_Account"]   = nameuser;
            ViewData["PostType"]       = new SelectList(_context.Post_Type, "ID_PostType", "Description", post.PostType);
            ViewData["Project"]        = new SelectList(_context.project, "id", "_name", post.Project);
            ViewData["RealEstateType"] = new SelectList(_context.RealEstate_Type, "ID_RealEstateType", "Description", post.RealEstateType);
            ViewData["Province"]       = new SelectList(_context.province.OrderBy(p => p._name), "id", "_name", Province);
            ViewData["District"]       = new SelectList(_context.district.OrderBy(p => p._name).Where(p => p._province_id == Province), "id", "_name", District);
            ViewData["Ward"]           = new SelectList(_context.ward.OrderBy(p => p._name).Where(p => p._province_id == Province && p._district_id == District), "id", "_name", Ward);
            ViewData["Street"]         = new SelectList(_context.street.OrderBy(p => p._name).Where(p => p._province_id == Province && p._district_id == District), "id", "_name", Street);
            return(View(post));
        }