public async Task <ResponseModel> AddSerieToList(string KeycloakId, int seriesID) { var exists = await _context.WatchLists.FirstOrDefaultAsync(x => x.UserId == KeycloakId && x.SeriesId == seriesID, cancellationToken); if (exists == null) { if (_context.AppUsers.FirstOrDefault(x => x.UserId == KeycloakId) != null) { await _context.WatchLists.AddAsync(new WatchList { SeriesId = seriesID, UserId = KeycloakId }, cancellationToken); await _context.SaveChangesAsync(cancellationToken); return(ResponseModel.ReturnSuccess()); } throw new Exception("User Not Found"); } throw new Exception("Show Already Added To WatchList"); }
public async Task <ResponseModel> RemoveMovieToList(string KeycloakId, int movieId) { var exists = _context.WatchLists.FirstOrDefault(x => x.UserId == KeycloakId && x.MovieId == movieId); if (exists != null) { _context.Remove(exists); _context.SaveChanges(); return(ResponseModel.ReturnSuccess()); } throw new Exception("Movie Already Removed From WatchList"); }
public async Task <ResponseModel> RemoveSerieToList(string KeycloakId, int seriesID) { var exists = await _context.WatchLists.FirstOrDefaultAsync(x => x.UserId == KeycloakId && x.SeriesId == seriesID, cancellationToken); if (exists != null) { _context.Remove(exists); _context.SaveChanges(); return(ResponseModel.ReturnSuccess()); } throw new Exception("Show Already Removed From WatchList"); }
public async Task <ResponseModel> AddMovie(MovieViewModel movies) { await _context.Movies.AddAsync(new Movie { Name = movies.Name.Trim().ToLower(), Path = movies.Path, Category = movies.Category, Description = movies.Description, Length = movies.Length, Thumbnail = movies.Thumbnail }, cancellationToken); await _context.SaveChangesAsync(cancellationToken); return(ResponseModel.ReturnSuccess()); }
public async Task <ResponseModel> AddSeries(SeriesViewModel series) { await _context.Series.AddAsync(new Series { SeriesName = series.SeriesName.Trim().ToLower(), ReleaseDate = series.ReleaseDate, SeriesDescription = series.SeriesDescription, NumberEpisodes = series.NumberEpisodes, Category = series.Category, SeriesThumbnail = series.SeriesThumbnail }, cancellationToken); await _context.SaveChangesAsync(cancellationToken); return(ResponseModel.ReturnSuccess()); }
public async Task <ResponseModel> AddSeriesList(SeriesListViewModel series) { var serie = _context.Series.FirstOrDefault(x => x.SeriesName == series.SeriesName); if (serie != null) { await _context.SeriesLists.AddAsync(new SeriesList { SeriesId = serie.Id, EpisodeLength = series.EpisodeLength, EpisodeName = series.EpisodeName, EpisodePath = series.EpisodePath }, cancellationToken); await _context.SaveChangesAsync(cancellationToken); return(ResponseModel.ReturnSuccess()); } throw new Exception("No Series Found"); }
public async Task <ResponseModel> AddUser(UsersViewModel usersViewModel) { var email = usersViewModel.Email.Trim().ToLower(); var existingUser = await _keycloakService.GetOneUserByEmailAsync(email); if (existingUser == null) { var keycloakUser = await _keycloakService.CreateUserAndSetPasswordAsync(new User { UserName = usersViewModel.Email, Email = usersViewModel.Email, Enabled = true, FirstName = usersViewModel.FirstName, LastName = usersViewModel.LastName }, usersViewModel.Password, new Dictionary <string, string> { { "Roles", "User" } }); if (keycloakUser == null) { throw new Exception("Something went wrong! Sign up has failed"); } _appUser = new AppUser { FirstName = usersViewModel.FirstName, LastName = usersViewModel.LastName, UserId = new Guid(keycloakUser.Id).ToString() }; _context.AppUsers.Add(_appUser); await _context.SaveChangesAsync(_cancellationToken); return(ResponseModel.ReturnSuccess()); } throw new Exception("User ALready Exist!"); }
public async Task <ResponseModel> Logout(LogoutRequest request) { _keycloakService.Logout(request); return(ResponseModel.ReturnSuccess()); }