public Response <List <Post> > GetPostsPaginationByStatusAndCategory(int offset, int maxAmount, string status, int categoryId) { var r = new Response <List <Post> >(); try { r.Success = true; r.Message = "Loaded posts."; r.Data = _postRepo.GetPostsPaginationByStatusAndCategory(offset, maxAmount, status, categoryId); foreach (Post p in r.Data) { p.CategoriesOnPost = _categoryOnPostRepo.GetAllCategoriesForPost(p.Id); p.TagsOnPost = _tagOnPostRepo.GetAllTagsForPost(p.Id); } } catch (Exception ex) { _exceptionsRepository.Add(ex); r.Success = false; r.Message = "Failed to load posts."; r.Data = new List <Post>(); } return(r); }
public Response <Blog> Update(Blog b) { var r = new Response <Blog>(); try { _blogRepository.Update(b); r.Success = true; r.Message = "Updated blog data"; r.Data = new Blog(); } catch (Exception ex) { _exceptionsRepository.Add(ex); r.Success = false; r.Message = "Failed to update blog data."; r.Data = new Blog(); } return(r); }
public Response <Category> GetByName(string name) { var r = new Response <Category>(); try { r.Success = true; r.Message = "Got category."; r.Data = _categoryRepository.GetByName(name); } catch (Exception ex) { _exceptionsRepository.Add(ex); r.Success = false; r.Message = "Failed to get category."; r.Data = new Category(); } return(r); }
public Response <int> Add(string name) { var response = new Response <int>(); try { response.Success = true; response.Message = "Added tag."; response.Data = _tagRepository.Add(name); } catch (Exception ex) { _exceptionsRepository.Add(ex); response.Success = false; response.Message = "Failed to add tag."; response.Data = 0; } return(response); }
public Response <int> Add(StaticPage sp) { var r = new Response <int>(); try { r.Success = true; r.Message = "Added static page."; r.Data = _staticPageRepository.Add(sp); } catch (Exception ex) { _exceptionsRepository.Add(ex); r.Success = false; r.Message = "Failed to add static page."; r.Data = 0; } return(r); }
public void CanWriteException() { _exceptionsRepository.Add(new Exception("This is an error message.")); Assert.AreEqual(1, _exceptionsRepository.GetAll().Count); }