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); }
public void UploadDocument(CMSDataContext db, Stream stream, string name, string mimetype) { var mdf = new MemberDocForm { PeopleId = PeopleId, DocDate = Util.Now, UploaderId = Util2.CurrentPeopleId, Name = Path.GetFileName(name).Truncate(100) }; db.MemberDocForms.InsertOnSubmit(mdf); var bits = new byte[stream.Length]; stream.Read(bits, 0, bits.Length); switch (mimetype) { case "image/jpeg": case "image/pjpeg": case "image/gif": case "image/png": mdf.IsDocument = false; mdf.SmallId = Image.NewImageFromBits(bits, 165, 220).Id; mdf.MediumId = Image.NewImageFromBits(bits, 675, 900).Id; mdf.LargeId = Image.NewImageFromBits(bits).Id; break; case "text/plain": case "application/pdf": case "application/msword": case "application/vnd.ms-excel": mdf.MediumId = 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); } db.SubmitChanges(); }
private void detach_MemberDocForms(MemberDocForm entity) { this.SendPropertyChanging(); entity.Person = null; }