Beispiel #1
0
 public bool Insert(tblRecord model)
 {
     int rowsAffected = -1;
     _db.tblRecords.AddOrUpdate(model);
     rowsAffected =  _db.SaveChanges();
     return rowsAffected >= 0;
 }
        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");
        }