public ActionResult Save(TinRaoBDS tinRaoBDS) { if (!ModelState.IsValid) { var errors = ModelState.Values.SelectMany(v => v.Errors); return(RedirectToAction("Index")); } var tinRaoInDb = _context.TinRaoBDSs.Single(x => x.Id == tinRaoBDS.Id); tinRaoInDb.TrangThai = tinRaoBDS.TrangThai; TempData["success"] = "Cập nhật thành công"; _context.SaveChanges(); return(RedirectToAction("Index")); }
public ActionResult Save(TinRaoBDS tinRaoBDS) { if (!ModelState.IsValid) { var errors = ModelState.Values.SelectMany(v => v.Errors); return(RedirectToAction("Index")); } tinRaoBDS.ThongTinMoTa = HttpUtility.HtmlDecode(tinRaoBDS.ThongTinMoTa); tinRaoBDS.Media = HttpUtility.HtmlDecode(tinRaoBDS.Media); if (tinRaoBDS.Id == 0) { var userId = User.Identity.GetUserId(); tinRaoBDS.AccountId = userId; tinRaoBDS.NgayTao = DateTime.Now; tinRaoBDS.TrangThai = 1; if (tinRaoBDS.ImageFile != null) { string uploadPath = ConfigurationManager.AppSettings["AnhDaiDienTinRao"].ToString(); tinRaoBDS.AnhDaiDien = saveFile(tinRaoBDS.ImageFile, uploadPath); } else { string uploadPath = ConfigurationManager.AppSettings["NoPhoto"].ToString(); tinRaoBDS.AnhDaiDien = uploadPath + "no-photo-available-300x225.png"; } TempData["success"] = "Thêm mới thành công"; _context.TinRaoBDSs.Add(tinRaoBDS); } else { var tinRaoInDB = _context.TinRaoBDSs.Single(x => x.Id == tinRaoBDS.Id); tinRaoInDB.TrangThai = tinRaoBDS.TrangThai; TempData["success"] = "Cập nhật thành công"; } _context.SaveChanges(); return(RedirectToAction("New")); }
public TinRaoViewModel(TinRaoBDS tinRaoBDS) { Id = tinRaoBDS.Id; LoaiTinRao = tinRaoBDS.LoaiTinRao; LoaiNhaDatId = tinRaoBDS.LoaiNhaDatId; TieuDe = tinRaoBDS.TieuDe; GiaTien = tinRaoBDS.GiaTien; TinhThanhPhoId = tinRaoBDS.TinhThanhPhoId; QuanHuyenId = tinRaoBDS.QuanHuyenId; DiaChi = tinRaoBDS.DiaChi; DienTich = tinRaoBDS.DienTich; ThongTinMoTa = tinRaoBDS.ThongTinMoTa; Media = tinRaoBDS.Media; TuKhoa = tinRaoBDS.TuKhoa; AnhDaiDien = tinRaoBDS.AnhDaiDien; HoTen = tinRaoBDS.HoTen; SoDienThoai = tinRaoBDS.SoDienThoai; Email = tinRaoBDS.Email; ThoiHanDangTin = tinRaoBDS.ThoiHanDangTin; AccountId = tinRaoBDS.AccountId; NgayTao = tinRaoBDS.NgayTao; TrangThai = tinRaoBDS.TrangThai; }