コード例 #1
0
 public ActionResult AddImage(ImageModel file, HttpPostedFileBase image)
 {
     if (!User.Identity.IsAuthenticated)
         return RedirectToAction("LogOn", "Account");
     if (ModelState.IsValid)
     {
         var scope = ObjectScopeProvider1.GetNewObjectScope();
         scope.Transaction.Begin();
         var productFile = new File { Filename = image.FileName };
         Stream fileStream = image.InputStream;
         int fileLength = image.ContentLength;
         productFile.Filedata = new byte[fileLength];
         fileStream.Read(productFile.Filedata, 0, fileLength);
         productFile.MimeType = image.ContentType;
         productFile.ID = DateTime.Now.Ticks.ToString();
         scope.Add((productFile));
         scope.Transaction.Commit();
         return RedirectToAction("Images");
     }
     return View(file);
 }
コード例 #2
0
 public ActionResult Ajaxaddimage(ImageModel file, HttpPostedFileBase image)
 {
     if (ModelState.IsValid)
     {
         var scope = ObjectScopeProvider1.GetNewObjectScope();
         scope.Transaction.Begin();
         var productFile = new File { Filename = image.FileName };
         Stream fileStream = image.InputStream;
         int fileLength = image.ContentLength;
         productFile.Filedata = new byte[fileLength];
         fileStream.Read(productFile.Filedata, 0, fileLength);
         productFile.MimeType = image.ContentType;
         productFile.ID = DateTime.Now.Ticks.ToString();
         scope.Add((productFile));
         scope.Transaction.Commit();
         ViewData["Status"] = "Image added successfully.";
         return View(new ImageModel());
     }
     return View(file);
 }