Ejemplo n.º 1
0
        //todo postdetail 頁面



        public IActionResult Post_Detail(int?id)
        {
            if (id != null)
            {
                var         query = db.TPosts.FirstOrDefault(p => p.FPostId == id);
                Post_Detail pd    = new Post_Detail {
                    post = query
                };
                return(View(pd));
            }
            return(View());
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> postSubmission([FromForm] Post_Detail post_Detail)
        {
            try
            {
                Owner owner = um.GetUser_Cookie(Request);
                Post  post  = new Post {
                    description = post_Detail.content
                };
                post.date_created = DateTime.Now;
                post.owner        = owner;
                post.modify_date  = DateTime.Now;
                var         path        = _env.WebRootPath;
                var         uploads     = Path.Combine(path, "files");
                List <Post> VideoImages = new List <Post>();
                if (post_Detail.files != null)
                {
                    foreach (IFormFile file in post_Detail.files)
                    {
                        string[] tokens    = file.ContentType.Split("/");
                        string   extension = System.IO.Path.GetExtension(file.FileName);
                        string   _id       = ObjectId.GenerateNewId().ToString();
                        await save_fileAsync(_id + System.IO.Path.GetFileNameWithoutExtension(file.FileName) + extension, uploads, file);

                        Post videoImage = new Post
                        {
                            _id          = _id,
                            type         = tokens[0],
                            link         = "/files/" + _id + System.IO.Path.GetFileNameWithoutExtension(file.FileName) + extension,
                            date_created = DateTime.Now,
                            modify_date  = DateTime.Now
                        };
                        VideoImages.Add(videoImage);
                    }
                    post.video_image = VideoImages;
                }
                await pm.insertPostAsync(post);

                return(Ok("Submit successfully"));
            }
            catch (Exception e)
            {
                Debug.WriteLine(e.StackTrace);
                return(BadRequest("Error from server"));
            }
        }
 public void Add_Post_Detail(int ID_Post, bool alley, int bedroom, int yard, int floor, bool nearSchool, bool nearAirport, bool nearHospital, bool nearMarket,
                             string descriptiondetail, int bathroom)
 {
     postdetail = new Post_Detail()
     {
         ID_Post      = ID_Post,
         Alley        = alley,
         Bathroom     = bathroom,
         Bedroom      = bedroom,
         Description  = descriptiondetail,
         Floor        = floor,
         Yard         = yard,
         NearHospital = nearHospital,
         NearAirport  = nearAirport,
         NearSchool   = nearSchool,
         NearMarket   = nearMarket,
     };
     DataProvider.Ins.db.Post_Detail.Add(postdetail);
     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));
        }