Ejemplo n.º 1
0
        public async Task <ActionResult> Post(PostAdminViewModel postViewModel, int[] selectedTag)
        {
            //var listTag = new List<Tag>();
            //foreach (var item in selectedTag)
            //{
            //    var tag = _repository.Tag.SingleOrDefault(m => m.ID == item);
            //    listTag.Add(tag);
            //}
            //var category = _repository.Category.SingleOrDefault(m => m.ID == postViewModel.Category);

            //postViewModel.Tags = listTag;
            //postViewModel.Category = category;

            //IMapper model = MappingConfig.MapperConfigPost.CreateMapper();
            //Post context = model.Map<Post>(post);

            //await _repository.ChangePostAsync(context);


            var tags = await _tagProvider.GetTagsByIdAsync(selectedTag);

            var categories = await _categoryProvider.GetCategoriesAsync();

            var category = categories.SingleOrDefault(m => m.Id == postViewModel.CategoryId);

            var post = _postMapper.ToPost(postViewModel, tags.ToList(), category);

            await _postProvider.ChangePostAsync(post);

            return(RedirectToAction("listPosts", "Home"));
        }
Ejemplo n.º 2
0
        public ActionResult Posts_Destroy([DataSourceRequest]DataSourceRequest request, PostAdminViewModel post)
        {
            if (post != null)
            {
                this.postsService.HardDelete(post.Id);
            }

            return this.Json(new[] { post }.ToDataSourceResult(request, this.ModelState));
        }
Ejemplo n.º 3
0
        private async Task TagData(PostAdminViewModel post)
        {
            var tags = await _tagProvider.GetTagsAsync();

            var postTag = new HashSet <int>(post.Tags.Select(c => c.Id));

            var tagsViewModel = _tagMapper.ToTagsViewModelByPostTag(tags, postTag);

            ViewBag.Tag = tagsViewModel;
        }
Ejemplo n.º 4
0
        public ActionResult Posts_Update([DataSourceRequest]DataSourceRequest request, PostAdminViewModel post)
        {
            if (this.ModelState.IsValid)
            {
                this.postsService.Update(post.Title, post.Content, post.IsDeleted, post.Id);
            }

            var postById = this.postsService.All(true).Where(x => x.Id == post.Id).FirstOrDefault();
            var data = this.Mapper.Map<PostAdminViewModel>(postById);
            return this.Json(new[] { data }.ToDataSourceResult(request, this.ModelState));
        }
Ejemplo n.º 5
0
        public async Task <ActionResult> Post(PostAdminViewModel postViewModel, int[] selectedTag)
        {
            var tags = await _tagProvider.GetTagsByIdAsync(selectedTag);

            var categories = await _categoryProvider.GetCategoriesAsync();

            var category = categories.FirstOrDefault(m => m.Id == postViewModel.CategoryId);

            var post = _postMapper.ToPost(postViewModel, tags, category);

            var toPost = await _postProvider.AddPostAsync(post);

            await _postProvider.AddReferencedToPost(toPost, selectedTag, postViewModel.CategoryId);

            return(RedirectToAction("Index", "Home"));
        }
Ejemplo n.º 6
0
        public Post ToPost(PostAdminViewModel postViewModel, List <Tag> tags, Category category)
        {
            var post = _mapper.Map <PostAdminViewModel, Post>(postViewModel);

            return(post);
        }
Ejemplo n.º 7
0
 private void TagDatas(PostAdminViewModel post)
 {
 }