예제 #1
0
        public ActionResult Contact(NoteBook model)
        {
            model.CreateDate = DateTime.Now;
            object imgCode = Session["ImgCode"];

            if (imgCode.ToString() != model.ValCode.ToUpper()) {
                ModelState.AddModelError("ValCode", "验证码输入有误");
            }

            if (!ModelState.IsValid) {
                return View();
            }
            try {
                context.NoteBook.Add(model);
                context.SaveChanges();
                TempData["SuccessMsg"] = "提交成功!我们将在第一时间和您联系!";
            }
            catch (Exception ex) {
                ModelState.AddModelError("DbError", ex.Message);
                return View();
            }

            return RedirectToAction("Contact");
        }
예제 #2
0
 public ActionResult EditNoteBook(NoteBook model)
 {
     if (!ModelState.IsValid) {
         return View();
     }
     if (model.Id == 0) {
         try {
             context.NoteBook.Add(model);
             context.SaveChanges();
         }
         catch (Exception ex) {
             ModelState.AddModelError("DbError", ex.Message);
         }
     }
     else {
         var old = context.NoteBook.SingleOrDefault(t => t.Id == model.Id);
         old.Name = model.Name;
         old.Surname = model.Surname;
         old.Company = model.Company;
         old.Country = model.Country;
         old.Email = model.Email;
         old.Message = model.Message;
         old.Phone = model.Phone;
         context.SaveChanges();
     }
     return View();
 }
예제 #3
0
 public ActionResult EditNoteBook(int? id)
 {
     var m = new NoteBook();
     if (id.HasValue) {
         var old = context.NoteBook.SingleOrDefault(t => t.Id == id.Value);
         m = old ?? m;
     }
     return View(m);
 }
예제 #4
0
 public ActionResult Contact()
 {
     var m = new NoteBook();
     return View(m);
 }