public async Task <ActionResult <PaginationApiResult <MeetingDTO> > > GetMeetings( string hostId = null, string guestId = null, int pageIndex = 0, int pageSize = 3) { var elements = _context.Meetings.Select(m => new MeetingDTO { Id = m.Id.ToString(), HostId = m.HostId, GuestId = m.GuestId, StartTime = m.StartTime, EndTime = m.EndTime, Notes = m.Notes, Accepted = m.Accepted, HostName = m.Host.Name, GuestName = m.Guest.Name, HostImgFilename = m.Host.ProfilePicFilename, GuestImgFilename = m.Guest.ProfilePicFilename }).OrderByDescending(m => m.StartTime); if (!string.IsNullOrEmpty(hostId)) { elements = (IOrderedQueryable <MeetingDTO>)elements.Where(m => m.HostId == hostId); } else if (!string.IsNullOrEmpty(guestId)) { elements = (IOrderedQueryable <MeetingDTO>)elements.Where(m => m.GuestId == guestId); } else { // protect from access to all meetings return(BadRequest()); } return(await PaginationApiResult <MeetingDTO> .CreateAsync(elements, pageIndex, pageSize)); }
public async Task <ActionResult <PaginationApiResult <MessageDTO> > > GetMessages( string id = null, string authorId = null, int pageIndex = 0, int pageSize = 10) { var elements = _context.Messages.Select(m => new MessageDTO() { Id = m.Id.ToString(), AuthorId = m.AuthorId, RecipentId = m.RecipentId, Content = m.Content, Read = m.Read, SentAt = m.SentAt, AuthorName = m.Author.Name, AuthorImgFilename = m.Author.ProfilePicFilename }); // protect from access to all messagess if (string.IsNullOrEmpty(id)) { return(BadRequest()); } if (string.IsNullOrEmpty(authorId)) { elements = elements.Where(m => m.RecipentId == id).OrderByDescending(m => m.SentAt); } else { // take all messages in a thread (both directions) elements = elements.Where(m => ((m.RecipentId == id && m.AuthorId == authorId) || (m.AuthorId == id && m.RecipentId == authorId))).OrderBy(m => m.SentAt); } return(await PaginationApiResult <MessageDTO> .CreateAsync(elements, pageIndex, pageSize)); }
public async Task <ActionResult <PaginationApiResult <MusiciansListDTO> > > GetMusicians( int pageIndex = 0, int pageSize = 3, int?type = null, string instrument = null, decimal minPrice = 0.0M, decimal maxPrice = 1000.0M, double minAvgScore = 0.0, int sort = 0) { // get elements from the database, filter and sort them return(await PaginationApiResult <MusiciansListDTO> .CreateAsync( _context.Musicians.Select(m => new MusiciansListDTO() { Id = m.Id, Email = m.Email, Name = m.Name, Price = m.Price, ProfilePicFilename = m.ProfilePicFilename, Instruments = m.Instruments, Types = m.Types, AvgScore = m.Reviews.Count != 0 ? (from r in m.Reviews select r.Rate).Average() : 0 }), pageIndex, pageSize, type, instrument, minPrice, maxPrice, minAvgScore, sort)); }
public async Task <ActionResult <PaginationApiResult <EmailMessageDTO> > > GetEmailMessage( string id = null, int pageIndex = 0, int pageSize = 3) { var elements = _context.EmailMessage.Select(m => new EmailMessageDTO() { Id = m.Id.ToString(), AuthorEmail = m.AuthorEmail, RecipentId = m.RecipentId, Content = m.Content, Read = m.Read, SentAt = m.SentAt }); // protect from access to all messagess if (string.IsNullOrEmpty(id)) { return(BadRequest()); } elements = elements.Where(m => m.RecipentId == id).OrderByDescending(m => m.SentAt); return(await PaginationApiResult <EmailMessageDTO> .CreateAsync(elements, pageIndex, pageSize)); }
public async Task <ActionResult <PaginationApiResult <ReviewsListDTO> > > GetReviews( int?top = null, string id = null, int pageIndex = 0, int pageSize = 3, string authorId = null) { var elements = _context.Reviews.Select(r => new ReviewsListDTO() { Id = r.Id.ToString(), Rate = r.Rate, Description = r.Description, AuthorName = r.Author.Name, AuthorProfilePicFilename = r.Author.ProfilePicFilename, TargetId = r.TargetId, TargetProfilePicFilename = r.Target.ProfilePicFilename, SentAt = r.SentAt, AuthorId = r.AuthorId, TargetName = r.Target.Name }).OrderByDescending(r => r.SentAt); if (top.HasValue) { pageSize = (int)top; elements = (IOrderedQueryable <ReviewsListDTO>)elements.Take((int)top); } if (!string.IsNullOrEmpty(id)) { elements = (IOrderedQueryable <ReviewsListDTO>)elements.Where(r => r.TargetId == id); } if (!string.IsNullOrEmpty(authorId)) { elements = (IOrderedQueryable <ReviewsListDTO>)elements.Where(r => r.AuthorId == authorId); } return(await PaginationApiResult <ReviewsListDTO> .CreateAsync( elements, pageIndex, pageSize)); }
public async Task <ActionResult <PaginationApiResult <ReportDTO> > > GetReports( string userId, int pageIndex = 0, int pageSize = 3) { var user = await _userManager.FindByIdAsync(userId); if (await _userManager.IsInRoleAsync(user, "Admin")) { var elements = _context.Reports.Select(r => new ReportDTO { Id = r.Id.ToString(), UserId = r.UserId, UserName = r.User.Name, ImgFilename = r.User.ProfilePicFilename, Justification = r.Justification, SentAt = r.SentAt }).OrderByDescending(r => r.SentAt); return(await PaginationApiResult <ReportDTO> .CreateAsync(elements, pageIndex, pageSize)); } else { return(BadRequest()); } }