public ActionResult Edit(DatBao item) { if (ModelState.IsValid) { if (item.DatBaoId == -1) { //item.UserModified = item.UserCreated = User.Username; //item.DateModified = item.DateCreated = DateTime.UtcNow; DatBaoManager.Instance.CreateItem(item); } else { var existingItem = DatBaoManager.Instance.GetItem(item.DatBaoId); existingItem.Status = item.Status; existingItem.LastModifiedOnDate = DateTime.UtcNow; //existingItem.LastModifiedUser = User.Username; DatBaoManager.Instance.UpdateItem(existingItem); } return(RedirectToDefaultRoute()); } else { return(View(item)); } }
public void UpdateItem(DatBao t) { using (IDataContext ctx = DataContext.Instance()) { var rep = ctx.GetRepository <DatBao>(); rep.Update(t); } }
public ActionResult Index() { var item = new DatBao(); ViewBag.Recaptcha = ReCaptcha.GetHtml(ConfigurationManager.AppSettings["ReCaptcha:SiteKey"]); ViewBag.publicKey = ConfigurationManager.AppSettings["ReCaptcha:SiteKey"]; return(View("Create", item)); }
public ActionResult Index(DatBao item) { var response = Request["g-recaptcha-response"]; string secretKey = ConfigurationManager.AppSettings["ReCaptcha:SecretKey"].ToString(); var client = new WebClient(); var result = client.DownloadString(string.Format("https://www.google.com/recaptcha/api/siteverify?secret={0}&response={1}", secretKey, response)); var obj = JObject.Parse(result); var status = (bool)obj.SelectToken("success"); ViewBag.RecaptchaLastErrors = status ? "" : "Google reCaptcha validation failed"; if (ModelState.IsValid && status) { if (item.DatBaoId == -1) { DatBaoManager.Instance.CreateItem(item); // send email to user and admin. string noidung = "Dear " + item.Ten + "," + Environment.NewLine; noidung += "Cám ơn bạn đã đặt báo tại Tòa soạn của chúng tôi. " + Environment.NewLine; noidung += "Thông tin đặt báo như sau :" + Environment.NewLine; noidung += "Tên: " + item.Ten + Environment.NewLine; noidung += "Địa chỉ: " + item.DiaChi + Environment.NewLine; noidung += "Điện thoại: " + item.DienThoai + Environment.NewLine; noidung += "Email: " + item.Email + Environment.NewLine; noidung += "Kỳ hạn: " + item.KyHan + " thang" + Environment.NewLine; noidung += "Nội dung: " + item.NoiDung + Environment.NewLine; noidung += "Hình thức thanh toán: " + item.HinhThucThanhToan == "TM" ? "Tiền mặt tại toàn soạn" : "Chuyển khoản " + Environment.NewLine + Environment.NewLine + Environment.NewLine + Environment.NewLine; noidung += "Trân trọng,"; //send mail to user Mail.SendEmail("*****@*****.**", item.Email, "Dat bao", noidung); // send mail to admin Mail.SendEmail("*****@*****.**", "*****@*****.**", "Dat bao", noidung); return(View("Thank", item)); } return(View("Create", item)); } else { return(View("Create", item)); } //return RedirectToDefaultRoute(); }