コード例 #1
0
        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);
        }
コード例 #2
0
        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()));
        }
コード例 #3
0
        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));
        }
コード例 #4
0
        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());
        }