コード例 #1
0
 public ActionResult Create(HttpPostedFileBase upload)
 {
     ValidateUploadedFile(upload);
     if (ModelState.IsValid)
     {
         if (upload != null && upload.ContentLength > 0)
         {
             try
             {
                 var stats = _fileAnalyzerClient.ComputeStatistics(upload);
                 var fileStatisticsEntity = new FileStatisticsEntity(stats);
                 _db.FileStatisticsEntities.Add(fileStatisticsEntity);
                 _db.SaveChanges();
                 return RedirectToAction("Index");
             }
             catch (Exception ex)
             {
                 ModelState.AddModelError(modalErrorKey, string.Format("Unexpected exception {0}", ex.Message));
             }
         }
     }
     return View();
 }
コード例 #2
0
        public ActionResult Edit(
            [Bind(Include = "ID")] FileStatisticsEntity fileStatisticsEntity, HttpPostedFileBase upload)
        {
            ValidateUploadedFile(upload);
            if (ModelState.IsValid)
            {
                if (fileStatisticsEntity == null)
                {
                    return HttpNotFound();
                }

                if (upload != null && upload.ContentLength > 0)
                {
                    try
                    {
                        var stats = _fileAnalyzerClient.ComputeStatistics(upload);
                        var newFileStatisticsEntity = new FileStatisticsEntity(stats) {ID = fileStatisticsEntity.ID};
                        _db.Entry(newFileStatisticsEntity).State = EntityState.Modified;
                        _db.SaveChanges();
                        return RedirectToAction("Index");
                    }
                    catch (Exception ex)
                    {
                        ModelState.AddModelError(modalErrorKey, string.Format("Unexpected exception {0}", ex.Message));
                    }
                }
            }
            return View();
        }