public async Task <IActionResult> PutPicture(int id, Picture picture) { var authorizedUser = await Authentication.GetAuthenticatedUserAsync(_context, Request); if (authorizedUser.Result is UnauthorizedResult) { return(Unauthorized()); } if (authorizedUser.Value == null) { return(Unauthorized()); } if (picture.ArtistId.HasValue && picture.ArtistId != authorizedUser.Value.Id) { return(Unauthorized()); } else if (picture.HostId.HasValue && picture.ArtistId != authorizedUser.Value.Id) { return(Unauthorized()); } else if (picture.EventId.HasValue) { Event @event = await _context.Events.FindAsync(picture.EventId.Value); if (@event == null) { return(BadRequest()); } else if (@event.HostId != authorizedUser.Value.Id) { return(Unauthorized()); } } if (id != picture.Id) { return(BadRequest()); } _context.Entry(picture).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!PictureExists(id)) { return(NotFound()); } else { throw; } } return(Ok()); }
public async Task <IActionResult> PutParticipation(int id, Participation participation) { var authorizedUser = await Authentication.GetAuthenticatedUserAsync(_context, Request); if (authorizedUser.Result is UnauthorizedResult) { return(Unauthorized()); } var @event = await _context.Events.FindAsync(participation.EventId); if (authorizedUser.Value == null) { return(Unauthorized()); } if (!(participation.ArtistId == authorizedUser.Value.Id || @event.HostId == authorizedUser.Value.Id)) { return(Unauthorized()); } if (id != participation.Id) { return(BadRequest()); } _context.Entry(participation).State = EntityState.Modified; try { await _context.SaveChangesAsync(); if (participation.ArtistId == authorizedUser.Value.Id) { Task.Run(() => NotifyHostUpdateAsync(participation.Id)); } else if (participation.Event.HostId == authorizedUser.Value.Id) { Task.Run(() => NotifyArtistUpdateAsync(participation.Id)); } } catch (DbUpdateConcurrencyException) { if (!ParticipationExists(id)) { return(NotFound()); } else { throw; } } return(Ok()); }
public async Task <ActionResult <Message> > PostMessage(Message message) { var authorizedUser = await Authentication.GetAuthenticatedUserAsync(_context, Request); if (authorizedUser.Result is UnauthorizedResult) { return(Unauthorized()); } if (authorizedUser.Value == null) { return(Unauthorized()); } if (message.AuthorId != authorizedUser.Value.Id) { return(Unauthorized()); } _context.Messages.Add(message); await _context.SaveChangesAsync(); if (message != null) { Task.Run(() => NotifyReceiverAsync(message.Id)); } //await NotifyReceiverAsync(message.Id); return(CreatedAtAction("GetMessage", new { id = message.Id }, message)); }
public async Task <IActionResult> PutFavorite(int id, Favorite favorite) { var authorizedUser = await Authentication.GetAuthenticatedUserAsync(_context, Request); if (authorizedUser.Result is UnauthorizedResult) { return(Unauthorized()); } if (authorizedUser.Value == null) { return(Unauthorized()); } if (favorite.ArtistId != authorizedUser.Value.Id) { return(Unauthorized()); } if (id != favorite.Id) { return(BadRequest()); } _context.Entry(favorite).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!FavoriteExists(id)) { return(NotFound()); } else { throw; } } return(Ok()); }
public async Task <IActionResult> GetUpdates() { DBInitializer.Run(); if (_context.SocialMedias.SingleOrDefault(s => s.Name == "Instagram") == null) { _context.SocialMedias.Add(new SocialMedia() { Name = "Instagram", Website = "https://www.instagram.com/" }); } await _context.SaveChangesAsync(); return(Ok()); }
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 <IActionResult> PutDeviceToken(int id, [FromBody] string deviceToken) { var authorizedUser = await Authentication.GetAuthenticatedUserAsync(_context, Request); if (authorizedUser.Result is UnauthorizedResult) { return(Unauthorized()); } if (authorizedUser.Value == null) { return(Unauthorized()); } if (authorizedUser.Value.Id != id) { return(Unauthorized()); } _context.UserIDs.Find(id).DeviceToken = deviceToken; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!UserIDExists(id)) { return(NotFound()); } else { throw; } } return(Ok()); }
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(); }