public Guid Login(LoginDTO UserModel) { try { using (GflixDBContext Context = new GflixDBContext()) { var User = (from user in Context.Users where user.UserName == UserModel.UserName && user.PasswordHash == UserModel.PasswordHash && user.IsActive == true select user).FirstOrDefault(); if (User != null) { User.SessionId = UserModel.SessionID; Context.SaveChanges(); return(UserModel.SessionID); } else { throw new CustomException("USER_NAME_OR_PASSWORD_INCORECT"); } } } catch (Exception ex) { throw new CustomException("DATABASE_INTERNAL_EXCEPTION"); } }
public void LogOut(Guid ID) { try { using (GflixDBContext Context = new GflixDBContext()) { var User = (from user in Context.Users where user.SessionId == ID && user.IsActive == true select user).FirstOrDefault(); if (User != null) { User.SessionId = null; Context.SaveChanges(); } else { throw new CustomException("SESSIONID_INCORECT"); } } } catch (Exception ex) { throw new CustomException("DATABASE_INTERNAL_EXCEPTION"); } }
public void WatchListAdd(Guid ID, Guid UserID) { try { using (GflixDBContext Context = new GflixDBContext()) { var WatchListData = (from watch in Context.WatchList where watch.UserId == UserID && watch.ContentId == ID select watch).FirstOrDefault(); if (WatchListData == null) { WatchList watch = new WatchList() { Id = Guid.NewGuid(), ContentId = ID, DateCreated = DateTime.Now, UserId = UserID }; Context.WatchList.Add(watch); Context.SaveChanges(); } } } catch (Exception ex) { throw new CustomException("DATABASE_INTERNAL_EXCEPTION"); } }
public UserDTO GetByID(Guid ID) { try { using (GflixDBContext Context = new GflixDBContext()) { var User = (from user in Context.Users where user.SessionId == ID || user.Id == ID select user).FirstOrDefault(); if (User != null) { return(new UserDTO() { ID = User.Id, Email = User.Email, PasswordHash = User.PasswordHash, UserName = User.UserName, Avatar = User.Avatar, SessionID = User.SessionId }); } else { throw new CustomException("USER_NOT_FOUND"); } } } catch (Exception ex) { throw new CustomException("DATABASE_INTERNAL_EXCEPTION"); } }
public PersonDTO GetByID(Guid ID) { try { using (GflixDBContext Context = new GflixDBContext()) { var PeopleData = (from people in Context.Peoples where people.Id == ID select people).Select(p => new PersonDTO() { ID = p.Id, Bio = p.Bio, Photo = p.Avatar, BornDate = p.BornDate, FirstName = p.FirstName, LastName = p.LastName, }).FirstOrDefault(); return(PeopleData); } } catch (Exception ex) { throw new CustomException("DATABASE_INTERNAL_EXCEPTION"); } }
public IEnumerable <PersonDTO> GetByContentID(Guid ID) { try { using (GflixDBContext Context = new GflixDBContext()) { var PeopleData = (from people in Context.Peoples join contentTopeople in Context.ContentToPeople on people.Id equals contentTopeople.PeopleId where contentTopeople.ContentId == ID select people).Select(p => new PersonDTO() { ID = p.Id, Bio = p.Bio, BornDate = p.BornDate, FirstName = p.FirstName, LastName = p.LastName, }).OrderBy(p => p.FirstName).ToList(); return(PeopleData); } } catch (Exception ex) { throw new CustomException("DATABASE_INTERNAL_EXCEPTION"); } }
public ContentDTO GetByID(Guid ID, Guid UserID) { try { using (GflixDBContext Context = new GflixDBContext()) { var ContentData = (from content in Context.Content where content.Id == ID select content).Select(p => new ContentDTO() { ID = p.Id, Title = p.Title, Description = p.Description, Trailer = p.TrailerUrl, Video = p.VideoUrl, ReleaseDate = p.ReleaseDate, Episode = p.Episode, Poster = p.Poster, Season = p.Season, Type = (ContentTypeEnum)p.Type, InWatchList = (from watch in Context.WatchList where watch.ContentId == p.Id && watch.UserId == UserID select watch).Any(), Genres = (from Genres in Context.Genres join GenresToContent in Context.ContentToGenres on Genres.Id equals GenresToContent.GenreId where GenresToContent.ContentId == p.Id select Genres).Select(p => new GenreDTO() { ID = p.Id, Name = p.Name, Description = p.Description, }).OrderBy(p => p.Name).ToList(), Persons = (from People in Context.Peoples join PeopleToContent in Context.ContentToPeople on People.Id equals PeopleToContent.PeopleId where PeopleToContent.ContentId == p.Id select new { People, PeopleToContent }).Select(p => new PersonDTO() { ID = p.People.Id, Bio = p.People.Bio, Position = p.PeopleToContent.CastType, BornDate = p.People.BornDate, FirstName = p.People.FirstName, LastName = p.People.LastName }).OrderBy(p => p.FirstName).ToList(), }).FirstOrDefault(); return(ContentData); } } catch (Exception ex) { throw new CustomException("DATABASE_INTERNAL_EXCEPTION"); } }
public IEnumerable <GenreDTO> GetAll() { try { using (GflixDBContext Context = new GflixDBContext()) { var GenreData = (from genres in Context.Genres select genres).Select(p => new GenreDTO() { ID = p.Id, Name = p.Name, Description = p.Description, }).OrderBy(p => p.Name).ToList(); return(GenreData); } } catch (Exception ex) { throw new CustomException("DATABASE_INTERNAL_EXCEPTION"); } }
public void Registration(UserDTO UserModel) { try { using (GflixDBContext Context = new GflixDBContext()) { var UserData = (from user in Context.Users where user.UserName == UserModel.UserName && user.Email == UserModel.Email select user).FirstOrDefault(); if (UserData == null) { Users NewUser = new Users() { Id = UserModel.ID, Email = UserModel.Email, Avatar = "", IsActive = true, PasswordHash = UserModel.PasswordHash, UserName = UserModel.UserName, DateCreated = DateTime.Now, }; Context.Users.Add(NewUser); Context.SaveChanges(); } else { throw new CustomException("USERNAME_OR_EMAIL_IS_USED"); } } } catch (Exception ex) { throw new CustomException("DATABASE_INTERNAL_EXCEPTION"); } }
public void WatchListRemove(Guid ID, Guid UserID) { try { using (GflixDBContext Context = new GflixDBContext()) { var WatchListData = (from watch in Context.WatchList where watch.UserId == UserID && watch.ContentId == ID select watch).FirstOrDefault(); if (WatchListData != null) { Context.WatchList.Remove(WatchListData); Context.SaveChanges(); } } } catch (Exception ex) { throw new CustomException("DATABASE_INTERNAL_EXCEPTION"); } }
public GenreDTO GetByID(Guid ID) { try { using (GflixDBContext Context = new GflixDBContext()) { var GenreData = (from genres in Context.Genres where genres.Id == ID select genres).Select(p => new GenreDTO() { ID = p.Id, Name = p.Name, Description = p.Description, }).FirstOrDefault(); return(GenreData); } } catch (Exception ex) { throw new CustomException("DATABASE_INTERNAL_EXCEPTION"); } }
public IEnumerable <GenreDTO> GetByContentID(Guid ID) { try { using (GflixDBContext Context = new GflixDBContext()) { var GenreData = (from genres in Context.Genres join contentTogenres in Context.ContentToGenres on genres.Id equals contentTogenres.GenreId where contentTogenres.ContentId == ID select genres).Select(p => new GenreDTO() { ID = p.Id, Name = p.Name, Description = p.Description, }).OrderBy(p => p.Name).ToList(); return(GenreData); } } catch (Exception ex) { throw new CustomException("DATABASE_INTERNAL_EXCEPTION"); } }
public IEnumerable <PersonDTO> GetAll() { try { using (GflixDBContext Context = new GflixDBContext()) { var PeopleData = (from people in Context.Peoples select people).Select(p => new PersonDTO() { ID = p.Id, Bio = p.Bio, BornDate = p.BornDate, FirstName = p.FirstName, LastName = p.LastName, }).OrderBy(p => p.FirstName).ToList(); return(PeopleData); } } catch (Exception ex) { throw new CustomException("DATABASE_INTERNAL_EXCEPTION"); } }