public ActionResult SaveNewDocument(FormCollection f) { string email = f["txtNew_email"].ToString(); if (ModelState.IsValid) { try { DangKyNhanThongBao dk = new DangKyNhanThongBao(); dk.email = email; dk.ngaydangky = DateTime.Now; db.DangKyNhanThongBao.Add(dk); db.SaveChanges(); } catch (Exception e) { ViewData["EditError"] = e.Message; } } else { ViewData["EditError"] = "Please, correct all errors."; } return(RedirectToAction("Index", "QuanLyEmailDangKy")); }
//-------------------------------------- Đăng ký nhận tin public ActionResult DangKyNhanTin(FormCollection f) { string txtEmail = f["txtEmail"].ToString(); var model = db.DangKyNhanThongBao; if (ModelState.IsValid) { try { var x = db.DangKyNhanThongBao.Where(n => n.email == txtEmail); if (x.Count() == 0) { DangKyNhanThongBao dknt = new DangKyNhanThongBao(); dknt.email = txtEmail; dknt.ngaydangky = DateTime.Now; db.DangKyNhanThongBao.Add(dknt); db.SaveChanges(); ViewBagData(); ViewBag.KetQua = "Đăng ký nhận tin thành công!"; return(View("Index")); } else { ViewBagData(); ViewBag.KetQua = "Email đã được đăng ký trước đó!"; return(View("Index")); } } catch (Exception e) { ViewData["EditError"] = e.Message; } } else { ViewData["EditError"] = "Please, correct all errors."; } return(null); }