예제 #1
0
        public ActionResult Create(EditPostViewModel viewModel, FormCollection collection, HttpPostedFileBase NewImage)
        {
            if (viewModel.Post.Id != 0)
            {
                return Edit(viewModel, collection, NewImage);
            }
            else
            {

            string s = collection["SelectedTagIds"];
            if (!string.IsNullOrEmpty(s))
            {
                string[] tagStrings = s.Split(',');

                viewModel.Post.Tags = new List<PostTag>();
                foreach (string tagString in tagStrings)
                {
                    viewModel.Post.Tags.Add(new PostTag()
                    {
                        Id = Int32.Parse(tagString)
                    });

                }
            }
            if (NewImage != null)
            {
                viewModel.Post.Images = new List<PostImage>();
                var image = PostImageBuilder.CreateFromPostedFile(NewImage);
                image.Caption = "";
                viewModel.Post.Images.Add(image);

            }

            if (viewModel.Post.IsJornal) {
                viewModel.Post.Id = int.Parse(DateTime.Now.ToString("ddmmyyy"));
            }
            _blogPostDao.Create(viewModel.Post);
            return RedirectToAction("Admin");
            }
        }
예제 #2
0
        public static EditPostViewModel GetNewEditPostViewModel()
        {
            IBlogPostDao _blogPostDao = new BlogPostDao_linq();
            var availibleTags = _blogPostDao.GetAllTags();

            EditPostViewModel viewModel = new EditPostViewModel
            {
                Post = new BlogPost { DateTime = DateTime.Now },
                EligiableTagList = new List<SelectListItem>(),
                SelectedTags = new List<PostTag>(),
                Images = new List<PostImage>()
            };

            foreach (var postTag in availibleTags)
            {
                viewModel.EligiableTagList.Add(new SelectListItem()
                {
                    Value = postTag.Id.ToString(),
                    Text = postTag.Tag
                });
            }
            return viewModel;
        }
예제 #3
0
        public ActionResult Edit(int id)
        {
            EditPostViewModel viewModel = new EditPostViewModel
            {
                Post = _blogPostDao.GetAny(id),
                EligiableTagList = new List<SelectListItem>()

            };

            viewModel.SelectedTagIds = viewModel.Post.Tags.Where(x => x.Id > 0).Select(z => z.Id).ToArray();

            foreach (var postTag in _blogPostDao.GetAllTags())
            {
                viewModel.EligiableTagList.Add(new SelectListItem()
                {
                    Value = postTag.Id.ToString(),
                    Text = postTag.Tag,

                     });
            }
            return View(viewModel);
        }
예제 #4
0
        public ActionResult Edit(EditPostViewModel viewModel, FormCollection collection, HttpPostedFileBase NewImage)
        {
            string s = collection["SelectedTagIds"];
            if (!string.IsNullOrEmpty(s))
            {
                string[] tagStrings = s.Split(',');

            viewModel.Post.Tags = new List<PostTag>();
            foreach (string tagString in tagStrings)
            {
                viewModel.Post.Tags.Add(new PostTag()
                {
                    Id = Int32.Parse(tagString)
                });

            }
            }
            if (NewImage != null)
            {
                UploadPicture(NewImage, viewModel.ImageCaption);
            }

            //todo: add an imamge to the DB without going through a post

            _blogPostDao.Update(viewModel.Post);
            return RedirectToAction("Admin");
        }