Пример #1
0
        public void DeleteUser(string userName)
        {
            User user = context.Users.Include(x => x.MoviesList).Include(x => x.Ratings).FirstOrDefault(x => x.UserName == userName);

            //Tag tag = context.Tags.Include(x => x.User).FirstOrDefault(x => x.User == user);
            //context.Tags.Remove()
            context.RemoveRange(context.Tags.Where(x => x.User.Id == user.Id));
            context.Users.Remove(user);
            context.SaveChanges();
        }
Пример #2
0
        public void Delete()
        {
            int    validator = 0;
            Movie  movie     = new Movie();
            string result    = null;
            string movieName = null;

            while (validate.ValidateMovieName(movieName) != 0)
            {
                Console.Write("\nName: ");
                movieName = Console.ReadLine().Trim().ToLower();
                if (validate.ValidateMovieName(movieName) != -1)
                {
                    movieName = movieName.First().ToString().ToUpper() + movieName.Substring(1);
                }
                validator = validate.ValidateMovieName(movieName);
                if (validator == 0)
                {
                    result = "Successfully deleted movie!";
                    break;
                }
                else if (validator == -1)
                {
                    result = "Name cannot be empty!";
                }
                else if (validator == 1)
                {
                    result = "Such movie doesn't exist!";
                }
                Console.WriteLine(result);
            }
            movie.Name = movieName;
            context.RemoveRange(context.Ratings.First(x => x.Movie.Name == movie.Name));

            context.Remove(context.Movies.First(x => x.Name == movie.Name));
            context.SaveChanges();
            Console.WriteLine(result);
        }