public ActionResult GetAllAnnotationsOfUser([FromQuery] PagingAttributes pagingAttributes) { (int userId, bool useridok) = GetAuthUserId(); if (!useridok) { return(Unauthorized()); } int count; var listOfAnnotations = _annotationService.GetAllAnnotationsOfUser(userId, pagingAttributes, out count); if (count == 0) { return(NotFound()); } foreach (PostAnnotationsDto item in listOfAnnotations) { var postDataForAnnot = _sharedService.GetPost(item.PostId); item.PostId = postDataForAnnot.Id; item.QuestionId = postDataForAnnot.QuestionId; item.Title = postDataForAnnot.Title; item.PostBody = postDataForAnnot.Body; item.PostUrl = SetPostUrl(postDataForAnnot.Id, postDataForAnnot.QuestionId); } return(Ok(CreateResult(listOfAnnotations, pagingAttributes, count))); }
public ActionResult SearchQuestionNoUser([FromQuery] PagingAttributes pagingAttributes, string queryString) { var userId = 1; var searchResults = _questionRepository.SearchQuestions(queryString, userId, pagingAttributes); return(Ok(CreateSearchResult(searchResults, queryString, userId, nameof(SearchQuestionNoUser), pagingAttributes))); }
private object CreateResult(IEnumerable <Searches> searches, int count, PagingAttributes attr) { if (searches.FirstOrDefault() != null) { var totalResults = count; var numberOfPages = Math.Ceiling((double)totalResults / attr.PageSize); var prev = attr.Page > 1 ? CreatePagingLink(attr.Page - 1, attr.PageSize) : null; var next = attr.Page < numberOfPages ? CreatePagingLink(attr.Page + 1, attr.PageSize) : null; return(new { totalResults, numberOfPages, prev, next, items = searches.Select(CreateSearchHistoryResultDto) }); } else { return(null); } }
public ActionResult QAGetUsers([FromQuery] PagingAttributes pagingAttributes) { var users = _dataService.QAGetUsers(pagingAttributes); var result = CreateResult(users, pagingAttributes); return(Ok(result)); }
private object CreateResult(IEnumerable <History> list, int count, PagingAttributes attr) { if (list.FirstOrDefault() != null) { var totalResults = count; var numberOfPages = Math.Ceiling((double)totalResults / attr.PageSize); var prev = attr.Page > 1 ? CreatePagingLink(nameof(GetHistory), attr.Page - 1, attr.PageSize) : null; var next = attr.Page < numberOfPages ? CreatePagingLink(nameof(GetHistory), attr.Page + 1, attr.PageSize) : null; return(new { totalResults, numberOfPages, prev, next, items = list.Select(CreateHistoryResultDto) //Select() is like a foreach loop }); } else { return(null); } }
public ActionResult SearchQuestion([FromQuery] PagingAttributes pagingAttributes, string queryString) { int.TryParse(HttpContext.User.Identity.Name, out var userId); var searchResults = _questionRepository.SearchQuestions(queryString, userId, pagingAttributes); return(Ok(CreateSearchResult(searchResults, queryString, userId, nameof(SearchQuestion), pagingAttributes))); }
//examples http://localhost:5001/api/questions // http://localhost:5001/api/questions?page=10&pageSize=5 // for browsing all the questions; with links to the thread public ActionResult BrowseQuestions([FromQuery] PagingAttributes pagingAttributes) { var categories = _dataService.GetQuestions(pagingAttributes); var result = CreateResult(categories, pagingAttributes); return(Ok(result)); }
public ActionResult GetPosts([FromQuery] PagingAttributes pagingAttributes) { var posts = _dataService.GetPosts(pagingAttributes); var result = CreateResult(posts, pagingAttributes); return(Ok(result)); }
private object CreateResult(IEnumerable <Note> notes, PagingAttributes attr, string userEmail = "", int questionId = 0) { int totalItems = 0; if (userEmail != "") { totalItems = _noteService.NumberOfNotesPerUser(userEmail); } if (questionId != 0) { totalItems = _noteService.NumberOfNotesPerQuestion(questionId); } var numberOfPages = Math.Ceiling((double)totalItems / attr.PageSize); var prev = attr.Page > 0 ? CreatePagingLink(attr.Page - 1, attr.PageSize, userEmail, questionId) : null; var next = attr.Page < numberOfPages - 1 ? CreatePagingLink(attr.Page + 1, attr.PageSize, userEmail, questionId) : null; return(new { totalItems, numberOfPages, prev, next, items = notes.Select(CreateNoteDto) }); }
public ActionResult GetNotes([FromQuery] PagingAttributes pagingAttributes) { var notes = _dataService.ReadAllNotes(pagingAttributes); var result = CreatedResult(notes, pagingAttributes); return(Ok(result)); }
public ActionResult GetAllMarkings([FromQuery] PagingAttributes pagingAttributes) { var markings = _dataService.GetAllMarkings(pagingAttributes); var result = CreatedResult(markings, pagingAttributes); return(Ok(result)); }
public ActionResult GetLinkPostIds([FromQuery] PagingAttributes pagingAttributes) { var linkpost = _dataService.GetLinkPostIds(pagingAttributes); var result = CreateResult(linkpost, pagingAttributes); return(Ok(result)); }
//example http://localhost:5001/api/history/searches public ActionResult GetSearchHistory([FromQuery] PagingAttributes pagingAttributes) { (int userId, bool useridok) = GetAuthUserId(); if (!useridok) { return(Unauthorized()); } (var shistory, int count) = _searchHistoryService.GetSearchesList(userId, pagingAttributes); if (shistory == null || count == 0) { //return NotFound(); shistory = new List <Searches>(); var dummyitem = new Searches(); shistory.Add(dummyitem); count = 0; } var result = CreateResult(shistory, count, pagingAttributes); if (result != null) { return(Ok(result)); } else { return(NoContent()); } }
public List <Note> GetAllNotesForQuestion(string userEmail, int questionId, PagingAttributes pagingAttributes) { using var db = new SovaDbContext(); return(db.Notes.Where(n => n.QuestionId == questionId && n.UserEmail == userEmail) .Skip(pagingAttributes.Page * pagingAttributes.PageSize) .Take(pagingAttributes.PageSize) .ToList()); }
public List <Notes> ReadAllNotes(PagingAttributes pagingAttributes) { SovaContext db = new SovaContext(); return(db.Notes .Skip(pagingAttributes.Page * pagingAttributes.PageSize) .Take(pagingAttributes.PageSize).ToList()); }
public List <History> ReadAll(int userId, PagingAttributes pagingAttributes) { SovaContext db = new SovaContext(); return(db.Histories.Skip(pagingAttributes.Page * pagingAttributes.PageSize).Take(pagingAttributes.PageSize).Where(x => x.userid == userId).ToList()); //return db.Histories.Where(x => x.userid == userId).Select(x => x).ToList(); }
public ActionResult GetMarkingsByUserEmail(string userEmail, [FromQuery] PagingAttributes pagingAttributes) { var markedQuestions = _questionService.GetAllMarkedQuestionsByUserEmail(userEmail, pagingAttributes); var result = CreateResult(markedQuestions, pagingAttributes, userEmail); return(Ok(result)); }
public IEnumerable <Question> GetQuestions(PagingAttributes pagingAttributes) { var randomOffSet = new Random().Next(1, 1000); return(_databaseContext.Questions.Include(q => q.Submission).ThenInclude(q => q.SoMember).Include(q => q.QuestionsTags).ThenInclude(q => q.Tag).Skip(randomOffSet).Skip(pagingAttributes.Page * pagingAttributes.PageSize) .Take(pagingAttributes.PageSize) .ToList()); }
/////////////////////// // // Users // /////////////////////// // Gets All GetUsers public IList <User> QAGetUsers(PagingAttributes pagingAttributes) { SovaContext db = new SovaContext(); return(db.Users.Skip(pagingAttributes.Page * pagingAttributes.PageSize) .Take(pagingAttributes.PageSize) .ToList()); }
/////////////////////// // // Posts // /////////////////////// // Gets All Posts public IList <Post> GetPosts(PagingAttributes pagingAttributes) { SovaContext db = new SovaContext(); return(db.Posts.Skip(pagingAttributes.Page * pagingAttributes.PageSize) .Take(pagingAttributes.PageSize) .ToList()); }
public List <FrameworkTables.User> GetUsers(PagingAttributes pagingAttributes) { SovaContext db = new SovaContext(); return(db.FrameworkUsers .Skip(pagingAttributes.Page * pagingAttributes.PageSize) .Take(pagingAttributes.PageSize).ToList()); }
public List <Marking> GetAllMarkings(PagingAttributes pagingAttributes) { SovaContext db = new SovaContext(); return(db.Markings .Skip(pagingAttributes.Page * pagingAttributes.PageSize) .Take(pagingAttributes.PageSize).ToList()); }
public List <Annotation> GetUserAnnotations(int userId, PagingAttributes pagingAttributes) { return(_databaseContext.Annotations.Include(a => a.Question) .Where(a => a.UserId == userId) .Skip(pagingAttributes.Page * pagingAttributes.PageSize) .Take(pagingAttributes.PageSize) .ToList()); }
public ActionResult GetAllNotesForQuestion(string userEmail, int questionId, [FromQuery] PagingAttributes pagingAttributes) { var notes = _noteService.GetAllNotesForQuestion(userEmail, questionId, pagingAttributes); var result = CreateResult(notes, pagingAttributes, userEmail); return(Ok(result)); }
public ActionResult GetNotesByUserEmail(string userEmail, [FromQuery] PagingAttributes pagingAttributes) { var notes = _noteService.GetNotesByUserEmail(userEmail, pagingAttributes); var result = CreateResult(notes, pagingAttributes, userEmail); return(Ok(result)); }
public void GetNotesByUserEmailTest() { var userEmail = "*****@*****.**"; var service = new NoteService(); var pagingAttributes = new PagingAttributes(); var result = service.GetNotesByUserEmail(userEmail, pagingAttributes); Assert.Equal(2, result.Count); }
public ActionResult GetQuestions([FromQuery] PagingAttributes pagingAttributes) { var questions = _dataService.GetQuestions(pagingAttributes); // var result = CreateResult(questions, pagingAttributes); var questionDtos = CreateQuestionDtos(questions); // return Ok(questionDtos); return(Ok(CreateResult(questionDtos, pagingAttributes))); }
public List <Note> GetNotesByUserEmail(string userEmail, PagingAttributes pagingAttributes) { using var db = new SovaDbContext(); return(db.Notes.Where(n => n.UserEmail == userEmail) .OrderBy(n => n.QuestionId) .Skip(pagingAttributes.Page * pagingAttributes.PageSize) .Take(pagingAttributes.PageSize) .ToList()); }
public List <Marking> GetMarkings(int userid, PagingAttributes pagingAttributes) { SovaContext db = new SovaContext(); return(db.Markings .Where(x => x.UserId == userid) .Skip(pagingAttributes.Page * pagingAttributes.PageSize) .Take(pagingAttributes.PageSize).ToList()); }
public void ReadAllTest() { var service = new NoteService(); var paging = new PagingAttributes(); var expected = service.ReadAllNotes() .Where(x => x.Userid == 1).Count(); Assert.AreEqual(expected, service.ReadAll(1, paging).Count); }