Exemplo n.º 1
0
        // GET: api/Posts/2
        public async Task <PostDto> Get(int id)
        {
            var post = await PostGenericFacade.GetAsync(id);

            if (post == null)
            {
                throw new HttpResponseException(HttpStatusCode.NotFound);
            }
            return(post);
        }
Exemplo n.º 2
0
        // DELETE: api/Posts/5
        public async Task <string> Delete(int id)
        {
            var success = await PostGenericFacade.DeleteAsync(id);

            if (!success)
            {
                throw new HttpResponseException(HttpStatusCode.NotFound);
            }
            return($"Deleted post with id: {id}");
        }
Exemplo n.º 3
0
        // PUT: api/Posts/5
        public async Task <string> Put(int id, PostDto entity)
        {
            if (!ModelState.IsValid)
            {
                throw new HttpResponseException(HttpStatusCode.BadRequest);
            }

            await PostGenericFacade.UpdateAsync(entity);

            return($"Updated post with id: {id}");
        }
Exemplo n.º 4
0
        public async Task <ActionResult> DeletePost(int id)
        {
            try
            {
                await PostGenericFacade.DeleteAsync(id);

                return(RedirectToAction("Index"));
            }
            catch
            {
                return(View());
            }
        }
Exemplo n.º 5
0
        public async Task <ActionResult> Edit(int id, PostDto post)
        {
            try
            {
                await PostGenericFacade.UpdateAsync(post);

                return(RedirectToAction("Index"));
            }
            catch
            {
                return(View());
            }
        }
Exemplo n.º 6
0
        // GET: api/Posts/GetByGroupId?groupId=666
        public async Task <IEnumerable <PostDto> > GetByGroupId(int groupId)
        {
            var groupDto = await GroupGenericFacade.GetAsync(groupId);

            if (groupDto == null)
            {
                throw new HttpResponseException(HttpStatusCode.NotFound);
            }

            var posts = await PostGenericFacade.GetPostsByGroupIdAsync(groupId);

            return(posts);
        }
Exemplo n.º 7
0
        // POST: api/Posts
        public async Task <string> Post(PostDto entity)
        {
            if (!ModelState.IsValid)
            {
                throw new HttpResponseException(HttpStatusCode.BadRequest);
            }
            var postId = await PostGenericFacade.CreateAsync(entity);

            if (postId.Equals(0))
            {
                throw new HttpResponseException(HttpStatusCode.BadRequest);
            }

            return($"Created Post with id: {postId}");
        }
Exemplo n.º 8
0
        // GET: api/Posts/GetByUserId?userId=666
        public async Task <IEnumerable <PostDto> > GetByUserId(int userId)
        {
            var userDto = await UserGenericFacade.GetAsync(userId);

            if (userDto == null)
            {
                throw new HttpResponseException(HttpStatusCode.NotFound);
            }

            //if (userDto.PostVisibilityPreference != Visibility.Visible)
            //    throw new HttpResponseException(HttpStatusCode.NotFound);

            var posts = await PostGenericFacade.GetPostsByUserIdAsync(userId);

            return(posts);
        }
Exemplo n.º 9
0
        private static PostGenericFacade CreateUserFacade(QueryResultDto <PostDto, PostFilterDto> expectedQueryResult)
        {
            var mockManager    = new FacadeMockManager();
            var uowMock        = FacadeMockManager.ConfigureUowMock();
            var mapper         = FacadeMockManager.ConfigureRealMapper();
            var repositoryMock = mockManager.ConfigureRepositoryMock <Post>();
            //Druhy zpusob porovnani, vice genericky nez v User testech ale mene presny
            var queryMock =
                mockManager.ConfigureQueryObjectMock <PostDto, Post, PostFilterDto>(
                    expectedQueryResult);
            var postService = new PostService(mapper, repositoryMock.Object, queryMock.Object);
            var crudService =
                new CrudQueryServiceBase <Post, PostDto, PostFilterDto>(mapper,
                                                                        repositoryMock.Object, queryMock.Object);
            var postFacade = new PostGenericFacade(uowMock.Object, crudService, postService);

            return(postFacade);
        }
Exemplo n.º 10
0
        //Pripravene akce - uzivatel je vsak zatim nedokaze spustit
        //----------------------------------------------------------

        // GET: Posts/UserProfile/5
        public async Task <ActionResult> Details(int id)
        {
            var model = await PostGenericFacade.GetAsync(id);

            return(View("PostDetailView", model));
        }