public EditRequestResult EditWebRequest(RequestSongViewModel editRequestModel, string username, bool isMod) { try { if (string.IsNullOrWhiteSpace(editRequestModel.Title) && string.IsNullOrWhiteSpace(editRequestModel.Artist)) { return(EditRequestResult.NoRequestEntered); } using (var context = _contextFactory.Create()) { var songRequest = context.SongRequests.SingleOrDefault(sr => sr.SongRequestId == editRequestModel.SongRequestId); if (songRequest == null) { return(EditRequestResult.UnSuccessful); } if (songRequest.Played) { return(EditRequestResult.RequestAlreadyRemoved); } if (!isMod && songRequest.RequestUsername != username) { return(EditRequestResult.NotYourRequest); } songRequest.RequestText = $"{editRequestModel.Artist} - {editRequestModel.Title} ({editRequestModel.SelectedInstrument})"; songRequest.InDrive = false; context.SaveChanges(); } } catch (Exception e) { _logger.LogError(e, $"Exception in EditWebRequest. editRequestModel: {editRequestModel}, username: {username}, isMod: {isMod}"); return(EditRequestResult.UnSuccessful); } UpdatePlaylists(); return(EditRequestResult.Success); }
public RequestSongPage() { InitializeComponent(); BindingContext = new RequestSongViewModel(Navigation); }
public AddRequestResult AddWebRequest(RequestSongViewModel requestSongViewModel, string username) { try { if (string.IsNullOrEmpty(requestSongViewModel.Title) && string.IsNullOrWhiteSpace(requestSongViewModel.Artist)) { return(AddRequestResult.NoRequestEntered); } var playlistState = GetPlaylistState(); switch (playlistState) { case PlaylistState.VeryClosed: return(AddRequestResult.PlaylistVeryClosed); case PlaylistState.Closed when !requestSongViewModel.IsVip: return(AddRequestResult.PlaylistClosed); } using (var context = _contextFactory.Create()) { if (!requestSongViewModel.IsVip && !requestSongViewModel.IsSuperVip) { var userSongCount = context.SongRequests.Count(sr => !sr.Played && sr.RequestUsername == username && sr.VipRequestTime == null); if (userSongCount >= UserMaxSongCount) { return(AddRequestResult.MaximumRegularRequests); } } var request = new SongRequest { RequestTime = DateTime.UtcNow, RequestText = $"{requestSongViewModel.Artist} - {requestSongViewModel.Title} ({requestSongViewModel.SelectedInstrument})", RequestUsername = username, Played = false }; if (requestSongViewModel.IsSuperVip) { request.VipRequestTime = DateTime.UtcNow; request.SuperVipRequestTime = DateTime.UtcNow; if (!_vipService.UseSuperVip(username)) { return(AddRequestResult.UnSuccessful); } } else if (requestSongViewModel.IsVip) { request.VipRequestTime = DateTime.UtcNow; if (!_vipService.UseVip(username)) { return(AddRequestResult.UnSuccessful); } } context.SongRequests.Add(request); context.SaveChanges(); } UpdatePlaylists(); } catch (Exception) { return(AddRequestResult.UnSuccessful); } return(AddRequestResult.Success); }