// GET: Record public ActionResult Index() { RecordDal db = new RecordDal(); List<tblRecord> records = db.GetRecords(); ViewBag.Records = records; return View("Index"); }
public ActionResult AddRecord(RecordModel model) { HttpPostedFileBase photo = Request.Files["file"]; this.Valid(model, photo); if (!ModelState.IsValid) { return View("Index", model); } else { string filePath = Path.Combine(HttpContext.Server.MapPath("../Uploads")); if (!Directory.Exists(filePath)) Directory.CreateDirectory(filePath); Debug.Assert(photo != null, "photo != null"); var fileName = Path.GetFileName(photo.FileName); Debug.Assert(fileName != null, "fileName != null"); photo.SaveAs(Path.Combine(filePath, fileName)); RecordDal db = new RecordDal(); tblRecord record = new tblRecord(); record.recorddate = model.RecordDate; record.distant = model.Distance; record.hour = model.Hour; record.minute = model.Minute; record.filepath = fileName; db.Insert(record); ViewBag.Message = Resource.Resource.RecordUploaded; } return View("Index"); }