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 JsonResult GetData(int idBV) { BaiViet bv = db.BaiViets.Where(x => x.idBV == idBV).SingleOrDefault(); NhaTro nt = db.NhaTroes.Where(x => x.idNT == bv.idNT).SingleOrDefault(); PostingModel view = new PostingModel(); view.TieuDe = bv.TieuDe; view.TieuDePhu = bv.TieuDePhu; view.NgayDang = bv.NgayDang; view.DienTich = nt.DienTich; view.Lau = (int)nt.Lau; view.PhongNgu = (int)nt.PhongNgu; view.NhaTam = (int)nt.NhaTam; view.MoTa = bv.MoTa; view.SoNha = nt.SoNha; view.Gia = (int)nt.Gia; view.idQuan = (int)nt.idQuan; view.idPhuong = (int)nt.idPhuong; view.idBV = idBV; string value = string.Empty; value = JsonConvert.SerializeObject(view, Formatting.Indented, new JsonSerializerSettings { ReferenceLoopHandling = ReferenceLoopHandling.Ignore }); return(Json(value, JsonRequestBehavior.AllowGet)); }
public ActionResult DeleteConfirmed(int id) { PostingModel postingModel = db.PostingModels.Find(id); db.PostingModels.Remove(postingModel); db.SaveChanges(); return(RedirectToAction("Index")); }
public ActionResult Edit([Bind(Include = "Id,Title,NutritionistId,CustomerId,PostTime,Content")] PostingModel postingModel) { if (ModelState.IsValid) { db.Entry(postingModel).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(postingModel)); }
public ActionResult Create([Bind(Include = "Id,Title,NutritionistId,CustomerId,PostTime,Content")] PostingModel postingModel) { if (ModelState.IsValid) { db.PostingModels.Add(postingModel); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(postingModel)); }
// GET: PostingModels/Delete/5 public ActionResult Delete(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } PostingModel postingModel = db.PostingModels.Find(id); if (postingModel == null) { return(HttpNotFound()); } return(View(postingModel)); }
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 Posting([Bind(Include = "Title,CustomerId,Contents")] PostingViewModel postingViewModel) { var CutomerName = _context.Users.Where(x => x.Roles.Select(y => y.RoleId).Contains("1")).ToList(); postingViewModel.ApplicationUser = CutomerName; if (ModelState.IsValid) { PostingModel postingModel = new PostingModel() { Title = postingViewModel.Title, NutritionistId = User.Identity.GetUserId(), CustomerId = postingViewModel.CustomerId, PostTime = DateTime.Now, Content = postingViewModel.Contents }; _context.PostingModels.Add(postingModel); _context.SaveChanges(); return(RedirectToAction("Index", "Home")); } return(View(postingViewModel)); }
public ActionResult PostingExample(PostingModel model) { return Content("Submitted!"); }