public ActionResult Create(EventViewModel model, HttpPostedFileBase upload) { if (this.ModelState.IsValid) { var eventToAdd = new Event { Title = model.Title, Description = HttpUtility.HtmlDecode(model.Description), CreatorId = this.User.Identity.GetUserId() }; if (upload != null && upload.ContentLength > 0) { var photo = new Data.Models.File { FileName = Path.GetFileName(upload.FileName), FileType = FileType.Photo, ContentType = upload.ContentType }; using (var reader = new BinaryReader(upload.InputStream)) { photo.Content = reader.ReadBytes(upload.ContentLength); } eventToAdd.Photo = photo; this.events.Add(eventToAdd); } return this.RedirectToAction("Index"); } return this.View(model); }
public ActionResult Create(PostViewModel post, HttpPostedFileBase upload) { if (this.ModelState.IsValid) { var postToAdd = new Post { Title = post.Title, Content = post.Content, CreatorId = this.User.Identity.GetUserId() }; if (upload != null && upload.ContentLength > 0) { var photo = new Data.Models.File { FileName = Path.GetFileName(upload.FileName), FileType = FileType.Photo, ContentType = upload.ContentType }; using (var reader = new BinaryReader(upload.InputStream)) { photo.Content = reader.ReadBytes(upload.ContentLength); } postToAdd.Photo = photo; } this.posts.Add(postToAdd); } return(this.Redirect(this.Request.UrlReferrer.ToString())); }
public ActionResult Create(ArticleViewModel model, HttpPostedFileBase upload) { if (this.ModelState.IsValid) { var articleToAdd = new Article { Title = model.Title, Content = HttpUtility.HtmlDecode(model.Content), CreatorId = this.User.Identity.GetUserId() }; if (upload != null && upload.ContentLength > 0) { var photo = new Data.Models.File { FileName = Path.GetFileName(upload.FileName), FileType = FileType.Photo, ContentType = upload.ContentType }; using (var reader = new BinaryReader(upload.InputStream)) { photo.Content = reader.ReadBytes(upload.ContentLength); } articleToAdd.Photo = photo; } this.articles.Add(articleToAdd); return(this.RedirectToAction("Index")); } return(this.View(model)); }
public ActionResult Create(PostViewModel post, HttpPostedFileBase upload) { if (this.ModelState.IsValid) { var postToAdd = new Post { Title = post.Title, Content = post.Content, CreatorId = this.User.Identity.GetUserId() }; if (upload != null && upload.ContentLength > 0) { var photo = new Data.Models.File { FileName = Path.GetFileName(upload.FileName), FileType = FileType.Photo, ContentType = upload.ContentType }; using (var reader = new BinaryReader(upload.InputStream)) { photo.Content = reader.ReadBytes(upload.ContentLength); } postToAdd.Photo = photo; } this.posts.Add(postToAdd); } return this.Redirect(this.Request.UrlReferrer.ToString()); }