public ActionResult Detail(int id) { var baiviet = new BaiVietDAO().GetByID(id); var nhatro = new NhaTroDAO().GetByID(baiviet.idNT); var taikhoan = new UserDAO().GetByID(baiviet.idTK); var result = new List <DetailModel>(); result.Add(new DetailModel { idBV = baiviet.idBV, tieude = baiviet.TieuDe, mota = baiviet.MoTa, ngaydang = baiviet.NgayDang.ToString().Substring(0, 10), hotentk = taikhoan.HoTen, ngaythamgia = taikhoan.NgayTao.ToString().Substring(0, 10), email = taikhoan.Email, phone = taikhoan.SDT, gia = nhatro.Gia, lau = nhatro.Lau, phongngu = nhatro.PhongNgu, nhatam = nhatro.NhaTam, dientich = nhatro.DienTich }); ViewBag.comment = db.Comments.SqlQuery("Select * from Comment c where c.idBV = " + id); ViewBag.Detail = result; ViewBag.listnew = db.BaiViets.SqlQuery("select * from BaiViet where NgayDang >= GETDATE()").ToList(); return(View()); }
public ActionResult SuaBaiViet(int idbv) { var bv = db.BaiViets.Find(idbv); var nt = new NhaTroDAO().GetByID(bv.idNT); var tk = new UserDAO().GetByID(bv.idTK); var result = new List <DetailModel>(); result.Add(new DetailModel { idBV = bv.idBV, tieude = bv.TieuDe, tieudephu = bv.TieuDePhu, mota = bv.MoTa, ngaydang = bv.NgayDang.ToString().Substring(0, 10), hotentk = tk.HoTen, ngaythamgia = tk.NgayTao.ToString().Substring(0, 10), email = tk.Email, phone = tk.SDT, gia = nt.Gia, lau = nt.Lau, phongngu = nt.PhongNgu, nhatam = nt.NhaTam, dientich = nt.DienTich }); ViewBag.TP = db.ThanhPhoes.ToList(); ViewBag.Quan = db.Quans.ToList(); ViewBag.Phuong = db.Phuongs.ToList(); ViewBag.LoaiBDS = db.LoaiBDS.ToList(); ViewBag.Detail = result; return(View(bv)); }
public ActionResult SuaBaiViet(PostingModel model) { BaiViet bv = db.BaiViets.Find(model.idBV); NhaTro nt = db.NhaTroes.Find(bv.idNT); bv.TieuDe = model.TieuDe; bv.TieuDePhu = model.TieuDePhu; bv.MoTa = model.MoTa; nt.SoNha = model.SoNha; nt.Gia = model.Gia; nt.Lau = model.Lau; nt.idPhuong = model.idPhuong; nt.idQuan = model.idQuan; nt.PhongNgu = model.PhongNgu; nt.NhaTam = model.NhaTam; var bvdao = new BaiVietDAO(); bvdao.Update(bv); var ntdao = new NhaTroDAO(); int idnt = (int)bv.idNT; ntdao.Update(nt, idnt); return(RedirectToAction("PostsManager", "Posting")); }
public ActionResult Posting(PostingModel model) { if (ModelState.IsValid) { if (model.ImageUpload != null) { string fileName = Path.GetFileNameWithoutExtension(model.ImageUpload.FileName); //string extension = Path.GetExtension(model.ImageUpload.FileName); //file.SaveAs(Server.MapPath("~/Content/Images/" + file.FileName)); model.Images = "~/Content/Images/" + fileName; } var daoNT = new NhaTroDAO(); var daoPost = new BaiVietDAO(); var bv = new BaiViet(); var nt = new NhaTro(); nt.DienTich = model.DienTich; nt.PhongNgu = model.PhongNgu; nt.Lau = model.Lau; nt.NhaTam = model.NhaTam; nt.Gia = model.Gia; nt.SoNha = model.SoNha; nt.idPhuong = model.idPhuong; nt.Image = model.Images; nt.idQuan = model.idQuan; daoNT.Insert(nt); NhaTro temp = db.NhaTroes.OrderByDescending(p => p.idNT).FirstOrDefault(); bv.TieuDe = model.TieuDe; bv.TieuDePhu = model.TieuDePhu; bv.MoTa = model.MoTa; bv.TrangThai = false; DateTime now = DateTime.Now; bv.NgayDang = now; bv.idNT = temp.idNT; var session = (DACN.Common.UserLogin)Session[DACN.Common.CommonConstants.USER_SESSION]; string ten = session.UserName; TaiKhoan tk = db.TaiKhoans.Find(session.userID); bv.idTK = tk.idTK; daoPost.Insert(bv); } return(View("Posted", model)); }
public ActionResult SuaBaiViet(DetailModel model) { var bv = db.BaiViets.Find(model.idBV); var nt = new NhaTroDAO().GetByID(bv.idNT); bv.TieuDe = model.tieude; bv.TieuDePhu = model.tieudephu; bv.MoTa = model.mota; nt.Lau = model.lau; nt.NhaTam = model.nhatam; nt.PhongNgu = model.phongngu; nt.DienTich = model.dientich; var bvdao = new BaiVietDAO(); bvdao.Update(bv); var ntdao = new NhaTroDAO(); int idnt = (int)bv.idNT; ntdao.Update(nt, idnt); return(RedirectToAction("QLBV", "Home")); }