Beispiel #1
0
        public ActionResult Create(PostInfo postInfo)
        {
            if (ModelState.IsValid)
            {
                
                var post = (Post)ModelMapper.Map(postInfo, typeof(PostInfo), typeof(Post));

                var audio = Request.Files["audio"];
                if (audio != null && audio.ContentLength > 0)
                {
                    var audioContent = new AudioContent();
                    audioContent.Name = audio.FileName;
                    var audioArray = new byte[audio.ContentLength];
                    audio.InputStream.Read(audioArray, 0, audio.ContentLength);
                    audioContent.AudioStream = audioArray;
                    post.AudioContent = audioContent;
                }

                post.DateCreated = DateTime.Now;
                post.UserPosted = userRepository.GetUser(CurrentUser.UserId);
                postRepository.SavePost(post);
                return RedirectToAction("List", "Post");
                
            }

            return View(postInfo);
        }
Beispiel #2
0
        public ActionResult Edit(PostInfo postInfo)
        {
            if (ModelState.IsValid)
            {
                var post = postRepository.GetPost(postInfo.PostId);
                post.Header = postInfo.Header;
                post.Content = postInfo.Content;
                post.DateLastEdited = DateTime.Now;
                postRepository.SavePost(post);
                return RedirectToAction("List", "Post");

            }

            return View(postInfo);
        }