public User LogUser(User user) { DataModelContainer ctx = DataModelContainer.GetDb(); return(ctx.UserSet .Where(u => u.Login == user.Login && user.Password == u.Password) .Select(u => u).FirstOrDefault()); }
public bool DeleteMovie(Movie movie) { DataModelContainer ctx = DataModelContainer.GetDb(); Movie toDelete = ctx.MovieSet.Where(m => m.Id == movie.Id).FirstOrDefault(); ctx.MovieSet.Remove(toDelete); ctx.SaveChanges(); return(true); }
public bool DeleteUser(User user) { DataModelContainer ctx = DataModelContainer.GetDb(); User toDelete = ctx.UserSet.Where(u => u.Id == user.Id).FirstOrDefault(); ctx.UserSet.Remove(toDelete); ctx.SaveChanges(); return(true); }
public User CreateUser(User user) { DataModelContainer ctx = DataModelContainer.GetDb(); Console.WriteLine("user in create: " + user.Login); ctx.UserSet.Add(user); ctx.SaveChanges(); return(user); }
public bool DeleteComment(Comment comment) { DataModelContainer ctx = DataModelContainer.GetDb(); Comment toDelete = ctx.CommentSet.Where(c => c.Id == comment.Id).FirstOrDefault(); ctx.CommentSet.Remove(toDelete); ctx.SaveChanges(); return(true); }
public Movie CreateMovie(Movie movie) { DataModelContainer ctx = DataModelContainer.GetDb(); Console.WriteLine("movie in create: " + movie.Title); ctx.MovieSet.Add(movie); ctx.SaveChanges(); return(movie); }
public Comment CreateComment(Comment comment) { DataModelContainer ctx = DataModelContainer.GetDb(); Console.WriteLine("comment in create: " + comment.ToString()); ctx.MovieSet.Attach(comment.Movie); ctx.UserSet.Attach(comment.User); ctx.CommentSet.Add(comment); ctx.SaveChanges(); return(comment); }
public User UpdateUser(User user) { Console.WriteLine("User passed to update: " + user.ToString()); DataModelContainer ctx = DataModelContainer.GetDb(); User toUpdate = ctx.UserSet.Where(u => u.Id == user.Id).FirstOrDefault(); Console.WriteLine("In UpdateUser, return of update method: " + toUpdate.ToString()); toUpdate.Firstname = user.Firstname; toUpdate.Lastname = user.Lastname; toUpdate.Login = user.Login; toUpdate.Password = user.Password; if (toUpdate.Equals(user)) { Console.WriteLine("Update ok"); ctx.SaveChanges(); return(toUpdate); } else { throw new Exception("Update failed"); } }
public Comment UpdateComment(Comment comment) { Console.WriteLine("Comment passed to update: " + comment.ToString()); DataModelContainer ctx = DataModelContainer.GetDb(); Comment toUpdate = ctx.CommentSet.Where(c => c.Id == comment.Id).FirstOrDefault(); Console.WriteLine("In UpdateComment, return of update method: " + toUpdate.ToString()); toUpdate.Message = comment.Message; toUpdate.Movie = comment.Movie; toUpdate.Note = comment.Note; toUpdate.User = comment.User; if (toUpdate.Equals(comment)) { Console.WriteLine("Update ok"); ctx.SaveChanges(); return(toUpdate); } else { throw new Exception("Update comment failed"); } }
public Movie UpdateMovie(Movie movie) { Console.WriteLine("Movie passed to update: " + movie.ToString()); DataModelContainer ctx = DataModelContainer.GetDb(); Movie toUpdate = ctx.MovieSet.Where(m => m.Id == movie.Id).FirstOrDefault(); Console.WriteLine("In UpdateMovie, return of update method: " + toUpdate.ToString()); toUpdate.Title = movie.Title; toUpdate.Type = movie.Type; toUpdate.Abstract = movie.Abstract; toUpdate.Comments = movie.Comments; if (toUpdate.Equals(movie)) { Console.WriteLine("Update ok"); ctx.SaveChanges(); return(toUpdate); } else { throw new Exception("Update movie failed"); } }
public User GetUser(int uid) { DataModelContainer ctx = DataModelContainer.GetDb(); return(ctx.UserSet.Where(u => u.Id == uid).FirstOrDefault()); }
public List <User> getAllUsers() { DataModelContainer ctx = DataModelContainer.GetDb(); return(ctx.UserSet.ToList()); }
public Comment GetComment(int cid) { DataModelContainer ctx = DataModelContainer.GetDb(); return(ctx.CommentSet.Where(c => c.Id == cid).FirstOrDefault()); }
public List <Comment> getAllComments() { DataModelContainer ctx = DataModelContainer.GetDb(); return(ctx.CommentSet.ToList()); }
public Movie GetMovie(int mid) { DataModelContainer ctx = DataModelContainer.GetDb(); return(ctx.MovieSet.Where(m => m.Id == mid).FirstOrDefault()); }
public List <Movie> getAllMovies() { DataModelContainer ctx = DataModelContainer.GetDb(); return(ctx.MovieSet.ToList()); }