Ejemplo n.º 1
0
        public ActionResult Index()
        {
            RecordModel model = new RecordModel();
            string code = Request.QueryString["code"];
            string state = Request.QueryString["state"];
            if (!string.IsNullOrEmpty(code))
            {
                model.OpenId = HttpHelper.GetOpenIdByAuthCode(code, state);
            }

            model.Distance = 0;
            model.RecordDate = DateTime.Now;
            ViewBag.Message = Resource.Resource.RecordDefault;
            return View(model);
        }
Ejemplo n.º 2
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");
        }
Ejemplo n.º 3
0
        public void Valid(RecordModel model, HttpPostedFileBase file)
        {
            if (file == null || file.ContentLength == 0)
            {
                ModelState.AddModelError("Id", Resource.Resource.RecordNoImage);
            }

            if (model.Distance <= 0)
            {
                ModelState.AddModelError("Distance", Resource.Resource.RecordNoDistant);
            }

            if (model.Hour <= 0 && model.Minute <=0)
            {
                ModelState.AddModelError("Hour", Resource.Resource.RecordNoTime);
            }
        }