public ActionResult Create(ThiSinh collection) { try { // TODO: Add insert logic here if (ModelState.IsValid) { byte[] imageData = null; HttpPostedFileBase poImgFile = Request.Files["fileim"]; if (poImgFile != null && poImgFile.ContentLength > 0) { using (var binary = new BinaryReader(poImgFile.InputStream)) { imageData = binary.ReadBytes(poImgFile.ContentLength); } } collection.Image = imageData; var ts = new ThiSinhData(); int id = ts.Insert(collection); if (id > 0) { return(RedirectToAction("Index", "ThiSinh")); } else { ModelState.AddModelError("", "Thêm thất bại"); } } return(View(collection)); } catch { return(View()); } }
public ActionResult Register(ThiSinh entity) { if (ModelState.IsValid) { var dao = new ThiSinhData(); var user = new ThiSinh(); user.GioiTinh = entity.GioiTinh; user.NgaySinh = entity.NgaySinh; user.DiaChi = entity.DiaChi; user.Image = entity.Image; user.Password = entity.Password; tn.SaveChanges(); if (dao.Insert(user) > 0) { ViewBag.Success = "Đăng ký thành công!"; entity = new ThiSinh(); } else { ModelState.AddModelError("", "Đăng ký không thành công!"); } } return(RedirectToAction("Index", "Login")); }