示例#1
0
 public ActionResult Upload(int id, HttpPostedFileBase file)
 {
     var m = new MemberDocs { PeopleId = id };
     try
     {
         var mdf = new MemberDocForm
         {
             PeopleId = id,
             DocDate = Util.Now,
             UploaderId = Util2.CurrentPeopleId,
             Name = System.IO.Path.GetFileName(file.FileName).Truncate(100)
         };
         DbUtil.Db.MemberDocForms.InsertOnSubmit(mdf);
         var bits = new byte[file.ContentLength];
         file.InputStream.Read(bits, 0, bits.Length);
         var mimetype = file.ContentType.ToLower();
         switch (mimetype)
         {
             case "image/jpeg":
             case "image/pjpeg":
             case "image/gif":
             case "image/png":
                 mdf.IsDocument = false;
                     mdf.SmallId = ImageData.Image.NewImageFromBits(bits, 165, 220).Id;
                     mdf.MediumId = ImageData.Image.NewImageFromBits(bits, 675, 900).Id;
                     mdf.LargeId = ImageData.Image.NewImageFromBits(bits).Id;
                 break;
             case "text/plain":
             case "application/pdf":
             case "application/msword":
             case "application/vnd.ms-excel":
                 mdf.MediumId = ImageData.Image.NewImageFromBits(bits, mimetype).Id;
                 mdf.SmallId = mdf.MediumId;
                 mdf.LargeId = mdf.MediumId;
                 mdf.IsDocument = true;
                 break;
             default:
                 throw new FormatException("file type not supported: " + mimetype);
         }
         DbUtil.Db.SubmitChanges();
         DbUtil.LogActivity("Uploading MemberDoc for {0}".Fmt(mdf.Person.Name));
     }
     catch (Exception ex)
     {
         ModelState.AddModelError("ImageFile", ex.Message);
         return View("Index", m);
     }
     return View("Index", m);
 }
示例#2
0
 public ActionResult Index(int id)
 {
     var m = new MemberDocs { PeopleId = id };
     return View(m);
 }