public async Task <Place> CreatePlace(Place place, string user) { if (!place.Owners.Any()) { place.Owners.Add(new Entities.Application.ListableUser { Id = user }); } if (place.MainPlaylist != null && place.MainPlaylist.Id != null && string.IsNullOrEmpty(place.MainPlaylist.Name)) { var dbUser = await this.userService.GetUser(user); var play = await this.playlistService.GetPlaylistFromSpotify(place.MainPlaylist.Id, dbUser.CurrentToken); if (play != null) { place.MainPlaylist = play; } } place.Geohash = GeoHash.Encode(place.Location.Latitude, place.Location.Longitude); var converted = _mapper.ToDbEntity(place); var dbResult = await _dao.CreatePlace(converted); if (place.MainPlaylist != null) { await this.playlistService.CreatePlaylist(dbResult.Reference.Id, place.MainPlaylist); } return(_mapper.ToApplicationEntity(dbResult)); }
public async Task <Entities.Application.Playlist> UpdatePlaylist(Place place, Dictionary <string, int> tags, Dictionary <string, int> genres) { var playlist = await this.playlistService.GetMainPlaylistFromPlace(place.Id, false, 0, 0); playlist.Tags = tags; playlist.Genres = genres; await this.playlistService.SetPlaylist(place.Id, playlist, false); return(playlist); }
public async Task <Place> UpdatePlace(Place place, string user) { var old = await this.GetPlace(place.Id); if (!old.Owners.Select(o => o.Id).Contains(user)) { throw new GrooverAuthException("Current User has no permissions to update this place"); } var fullUser = await this.userService.GetUser(user); var playlistNeedsUpdate = false; var dbFormat = PlaylistService.ParseSpotifyPlaylist(place.MainPlaylist.Id); if (old.MainPlaylist?.Id != dbFormat || (!old.MainPlaylist?.Songs?.Any() ?? true)) { old.MainPlaylist = await this.playlistService.GetPlaylistFromSpotify(place.MainPlaylist.Id, fullUser.CurrentToken); playlistNeedsUpdate = true; } old.DisplayName = place.DisplayName; old.Location = place.Location; old.Address = place.Address; old.PendingReview = !old.Approved; old.Phone = place.Phone; old.Timetables = place.Timetables; old.Geohash = GeoHash.Encode(old.Location.Latitude, old.Location.Longitude); var converted = _mapper.ToDbEntity(old); var dbResult = await _dao.UpdatePlace(converted); if (playlistNeedsUpdate) { await playlistService.SetPlaylist(old.Id, old.MainPlaylist, true); } return(_mapper.ToApplicationEntity(dbResult)); }