public async Task <ActionResult <IEnumerable <Message> > > GetMessages(int?receiver) { var authorizedUser = await Authentication.GetAuthenticatedUserAsync(_context, Request); if (authorizedUser.Result is UnauthorizedResult) { return(Unauthorized()); } if (authorizedUser.Value == null) { return(Unauthorized()); } using (var db = new GigFinderContext()) { if (!receiver.HasValue) { return(await db.Messages.Where(m => m.AuthorId == authorizedUser.Value.Id || m.ReceiverId == authorizedUser.Value.Id).ToListAsync()); } else { return(await db.Messages.Where(m => (m.AuthorId == authorizedUser.Value.Id && m.ReceiverId == receiver.Value) || (m.AuthorId == receiver.Value && m.ReceiverId == authorizedUser.Value.Id)).ToListAsync()); } } }
private async Task NotifyHostUpdateAsync(int id) { using (var db = new GigFinderContext()) { Participation participation = db.Participations.Include(p => p.Event.Host.UserId).Include(p => p.Artist).SingleOrDefault(m => m.Id == id); if (participation != null) { await GoogleServices.SendFCMAsync(participation.Event.Host.UserId.DeviceToken, "New participation update", $"{participation.Artist.Name} has updated the participation at your event {participation.Event.Title}"); } } }
// DELETE: api/Messages/5 //[HttpDelete("{id}")] //public async Task<ActionResult<Message>> DeleteMessage(int id) //{ // if (!Authentication.AuthenticateAsync(Request).Result) // return Unauthorized(); // // var message = await _context.Messages.FindAsync(id); // if (message == null) // { // return NotFound(); // } // _context.Messages.Remove(message); // await _context.SaveChangesAsync(); // return message; //} private async Task NotifyReceiverAsync(int id) { using (var db = new GigFinderContext()) { Message message = db.Messages.Include(m => m.Author.Host).Include(m => m.Author.Artist).SingleOrDefault(m => m.Id == id); if (message != null) { await GoogleServices.SendFCMAsync(message.Receiver.DeviceToken, $"New message from {message.Author.Host?.Name ?? message.Author.Artist?.Name}", message.Content); } } }
public static async Task <ActionResult <UserID> > GetAuthenticatedUserAsync(GigFinderContext context, HttpRequest httpRequest) { var payload = await GoogleServices.GetTokenPayloadAsync(GetIdToken(httpRequest)); if (payload == null) { return(new UnauthorizedResult()); } return(context.UserIDs.SingleOrDefault(u => u.GoogleIdToken == payload.Subject)); }
private async Task NotifyArtistUpdateAsync(int id) { using (var db = new GigFinderContext()) { Participation participation = db.Participations.Include(p => p.Artist.UserId).Include(p => p.Event).SingleOrDefault(m => m.Id == id); if (participation != null) { string partString = participation.Accepted ? "accepted" : "declined"; await GoogleServices.SendFCMAsync(participation.Artist.UserId.DeviceToken, "New participation update", $"Your participation at {participation.Event.Title} has been {partString}"); } } }
public static void Run() { using (var context = new GigFinderContext()) { if (!context.Genres.Any()) { InitGenreAsync(context); } if (!context.SocialMedias.Any()) { InitSocialMediaAsync(context); } } }
private async Task NotifyReceiverAsync(int id) { using (var db = new GigFinderContext()) { Review review = db.Reviews.Include(r => r.Author.Host).Include(r => r.Author.Artist).Include(r => r.Host.UserId).Include(r => r.Artist.UserId).SingleOrDefault(m => m.Id == id); if (review != null && review.Artist != null) { await GoogleServices.SendFCMAsync(review.Artist.UserId.DeviceToken, "New review", $"You have a new {review.Rating} star review from {review.Author.Host.UserId}"); } else if (review != null && review.Host != null) { await GoogleServices.SendFCMAsync(review.Host.UserId.DeviceToken, "New review", $"You have a new {review.Rating} star review from {review.Author.Artist.UserId}"); } } }
private static async void InitSocialMediaAsync(GigFinderContext context) { if (context == null) { throw new ArgumentNullException(nameof(context)); } context.SocialMedias.Add(new SocialMedia() { Name = "Soundcloud", Website = "https://soundcloud.com/" }); context.SocialMedias.Add(new SocialMedia() { Name = "Facebook", Website = "https://www.facebook.com/" }); context.SocialMedias.Add(new SocialMedia() { Name = "Twitter", Website = "https://twitter.com/" }); context.SocialMedias.Add(new SocialMedia() { Name = "YouTube", Website = "https://www.youtube.com/" }); context.SocialMedias.Add(new SocialMedia() { Name = "MySpace", Website = "https://myspace.com/" }); context.SocialMedias.Add(new SocialMedia() { Name = "last.fm", Website = "https://www.last.fm/" }); context.SocialMedias.Add(new SocialMedia() { Name = "Spotify", Website = "https://www.spotify.com/" }); context.SocialMedias.Add(new SocialMedia() { Name = "Instagram", Website = "https://www.instagram.com/" }); context.SocialMedias.Add(new SocialMedia() { Name = "Website", Website = "unset" }); await context.SaveChangesAsync(); }
public async Task <ActionResult <IEnumerable <Event> > > GetEvents(GeoPoint location, double?radius, int?genre, int?host, int?artist) { var authorizedUser = await Authentication.GetAuthenticatedUserAsync(_context, Request); if (authorizedUser.Result is UnauthorizedResult) { return(Unauthorized()); } if (authorizedUser.Value == null) { return(Unauthorized()); } using (var db = new GigFinderContext()) { if (location == null && !genre.HasValue && !host.HasValue && !artist.HasValue) { return(await db.Events.Include(h => h.EventGenres).Where(e => e.HostId == authorizedUser.Value.Id || e.Participations.Any(p => p.ArtistId == authorizedUser.Value.Id)).ToListAsync()); } var query = (IQueryable <Event>)db.Events.Include(h => h.EventGenres); if (location != null && radius.HasValue) { query = query.Where(e => GeoPoint.CalculateDistance(location, new GeoPoint() { Longitude = e.Longitude, Latitude = e.Latitude }) <= radius.Value); } if (genre.HasValue) { query = query.Where(e => e.EventGenres.Any(eg => eg.GenreId == genre)); } if (host.HasValue) { query = query.Where(e => e.HostId == host); } if (artist.HasValue) { query = query.Where(e => e.Participations.Any(p => p.ArtistId == artist)); } return(await query.ToListAsync()); } }
private async Task NotifySearchRequestsAsync(Event @event) { if (@event == null) { throw new ArgumentNullException(nameof(@event)); } using (var db = new GigFinderContext()) { foreach (var searchRequest in db.SearchRequests.Include(s => s.Artist.UserId)) { if (searchRequest.IsEventInRadius(@event)) { await GoogleServices.SendFCMAsync(searchRequest.Artist.UserId.DeviceToken, "New event in your search area", $"Event name: {@event.Title}\nHost: {@event.Host.Name}"); } } } }
public async Task <ActionResult <IEnumerable <object> > > GetReceivers() { var authorizedUser = await Authentication.GetAuthenticatedUserAsync(_context, Request); if (authorizedUser.Result is UnauthorizedResult) { return(Unauthorized()); } if (authorizedUser.Value == null) { return(Unauthorized()); } using (var db = new GigFinderContext()) { IEnumerable <int> receiverIds = db.Messages.Where(m => m.AuthorId == authorizedUser.Value.Id).Select(m => m.ReceiverId).Concat(db.Messages.Where(m => m.ReceiverId == authorizedUser.Value.Id).Select(m => m.AuthorId)).Distinct(); List <object> output = new List <object>(); foreach (int receiverId in receiverIds) { Artist receivingArtist = await db.Artists.FindAsync(receiverId); Host receivingHost = await db.Hosts.FindAsync(receiverId); Message lastMessage = db.Messages.Where(m => (m.AuthorId == authorizedUser.Value.Id && m.ReceiverId == receiverId) || (m.ReceiverId == authorizedUser.Value.Id && m.AuthorId == receiverId)).OrderBy(m => m.Created).Last(); if (receivingArtist != null) { output.Add(new { Artist = receivingArtist, LastMessage = lastMessage }); } else if (receivingHost != null) { output.Add(new { Host = receivingHost, LastMessage = lastMessage }); } else { output.Add(new { Id = receiverId, LastMessage = lastMessage }); } } return(output); } }
public GenresController(GigFinderContext context) { _context = context; }
public UpdatesController(GigFinderContext context) { _context = context; }
public ReceiversController(GigFinderContext context) { _context = context; }
public ParticipationsController(GigFinderContext context) { _context = context; }
public ReviewsController(GigFinderContext context) { _context = context; }
private static async void InitGenreAsync(GigFinderContext context) { if (context == null) { throw new ArgumentNullException(nameof(context)); } context.Genres.Add(new Genre() { Value = "Alternative" }); context.Genres.Add(new Genre() { Value = "Electronic" }); context.Genres.Add(new Genre() { Value = "Experimental" }); context.Genres.Add(new Genre() { Value = "Hip-Hop and Rap" }); context.Genres.Add(new Genre() { Value = "Trap" }); context.Genres.Add(new Genre() { Value = "Pop" }); context.Genres.Add(new Genre() { Value = "R&B" }); context.Genres.Add(new Genre() { Value = "Latino" }); context.Genres.Add(new Genre() { Value = "Rock" }); context.Genres.Add(new Genre() { Value = "Punk" }); context.Genres.Add(new Genre() { Value = "Metal" }); context.Genres.Add(new Genre() { Value = "Jazz" }); context.Genres.Add(new Genre() { Value = "Folk" }); context.Genres.Add(new Genre() { Value = "Techno" }); context.Genres.Add(new Genre() { Value = "House" }); context.Genres.Add(new Genre() { Value = "Singer Songwriter" }); await context.SaveChangesAsync(); }
public MessagesController(GigFinderContext context) { _context = context; }
public PicturesController(GigFinderContext context) { _context = context; }
public LoginController(GigFinderContext context) { _context = context; }
public EventsController(GigFinderContext context) { _context = context; }
public SocialMediasController(GigFinderContext context) { _context = context; }
public ArtistsController(GigFinderContext context) { _context = context; }
public FavoritesController(GigFinderContext context) { _context = context; }
public UserController(GigFinderContext context) { _context = context; }
public DeviceTokenController(GigFinderContext context) { _context = context; }
public SearchRequestsController(GigFinderContext context) { _context = context; }