Esempio n. 1
0
        public void InvalidRegisterShouldNotCerateANewUserWithTheSameUsername()
        {
            var options = new DbContextOptionsBuilder <MoviesDbContext>()
                          .UseInMemoryDatabase(databaseName: nameof(InvalidRegisterShouldNotCerateANewUserWithTheSameUsername))
                          .Options;

            using (var context = new MoviesDbContext(options))
            {
                var userService = new UserService(context, config);

                var added1 = new Lab2.ViewModels.RegisterPostModel
                {
                    Email     = "[email protected]",
                    FirstName = "asdf",
                    LastName  = "asdfgh",
                    Password  = "******",
                    Username  = "******"
                };
                var added2 = new Lab2.ViewModels.RegisterPostModel
                {
                    Email     = "[email protected]",
                    FirstName = "asdfg",
                    LastName  = "asdsdfgfgh",
                    Password  = "******",
                    Username  = "******"
                };

                userService.Register(added1);
                var result = userService.Register(added2);

                Assert.AreEqual(null, result);
            }
        }
Esempio n. 2
0
        public void CreateShouldReturnNullIfValidUserGetModel()
        {
            var options = new DbContextOptionsBuilder <MoviesDbContext>()
                          .UseInMemoryDatabase(databaseName: nameof(CreateShouldReturnNullIfValidUserGetModel))
                          .Options;

            using (var context = new MoviesDbContext(options))
            {
                var validator    = new RegisterValidator();
                var usersService = new UsersService(context, validator, null, config);

                UserRole addUserRoleRegular = new UserRole
                {
                    Name        = "Regular",
                    Description = "Creat pentru testare"
                };
                context.UserRole.Add(addUserRoleRegular);
                context.SaveChanges();

                var added1 = new Lab3Movie.ViewModels.RegisterPostModel
                {
                    FirstName = "firstName1",
                    LastName  = "firstName1",
                    UserName  = "******",
                    Email     = "*****@*****.**",
                    Password  = "******"
                };

                var userCreated = usersService.Create(added1);

                Assert.IsNull(userCreated);
            }
        }
Esempio n. 3
0
        public void GetAllShouldReturnAllRegisteredUsers()
        {
            var options = new DbContextOptionsBuilder <MoviesDbContext>()
                          .UseInMemoryDatabase(databaseName: nameof(GetAllShouldReturnAllRegisteredUsers))
                          .Options;

            using (var context = new MoviesDbContext(options))
            {
                var validator    = new RegisterValidator();
                var usersService = new UsersService(context, validator, null, config);
                var added1       = new Lab3Movie.ViewModels.RegisterPostModel
                {
                    FirstName = "firstName1",
                    LastName  = "firstName1",
                    UserName  = "******",
                    Email     = "*****@*****.**",
                    Password  = "******"
                };
                var added2 = new Lab3Movie.ViewModels.RegisterPostModel
                {
                    FirstName = "secondName2",
                    LastName  = "secondName2",
                    UserName  = "******",
                    Email     = "*****@*****.**",
                    Password  = "******"
                };
                usersService.Register(added1);
                usersService.Register(added2);

                int numberOfElements = usersService.GetAll().Count();

                Assert.NotZero(numberOfElements);
                Assert.AreEqual(2, numberOfElements);
            }
        }
Esempio n. 4
0
        public void InvalidRegisterShouldReturnErrorsCollection()
        {
            var options = new DbContextOptionsBuilder <MoviesDbContext>()
                          .UseInMemoryDatabase(databaseName: nameof(InvalidRegisterShouldReturnErrorsCollection))
                          .Options;

            using (var context = new MoviesDbContext(options))
            {
                var validator    = new RegisterValidator();
                var usersService = new UsersService(context, validator, null, config);
                var added        = new ExamenNet.ViewModels.RegisterPostModel
                {
                    FirstName = "firstName1",
                    LastName  = "lastName1",
                    UserName  = "******",
                    Email     = "*****@*****.**",
                    Password  = "******"   //invalid password should invalidate register
                };

                var result = usersService.Register(added);

                Assert.IsNotNull(result);
                Assert.AreEqual(1, result.ErrorMessages.Count());
            }
        }
Esempio n. 5
0
        public void DeleteShouldRemoveAndReturnUserRole()
        {
            var options = new DbContextOptionsBuilder <MoviesDbContext>()
                          .UseInMemoryDatabase(databaseName: nameof(DeleteShouldRemoveAndReturnUserRole))
                          .EnableSensitiveDataLogging()
                          .Options;

            using (var context = new MoviesDbContext(options))
            {
                var userRoleService = new UserRoleService(context);
                var addUserRole     = userRoleService.Create(new ExamenNet.ViewModels.UserRolePostModel
                {
                    Name        = "Rol testare",
                    Description = "Creat pentru testare"
                });

                Assert.IsNotNull(addUserRole);
                Assert.AreEqual("Rol testare", context.UserRoles.Find(1).Name);

                var deletedUserRole = userRoleService.Delete(1);

                Assert.IsNotNull(deletedUserRole);
                Assert.AreEqual(addUserRole.Name, deletedUserRole.Name);
            }
        }
Esempio n. 6
0
        public void UpsertShouldUpdateARoleOrAddANewOne()
        {
            var options = new DbContextOptionsBuilder <MoviesDbContext>()
                          .UseInMemoryDatabase(databaseName: nameof(UpsertShouldUpdateARoleOrAddANewOne))
                          .Options;

            using (var context = new MoviesDbContext(options))
            {
                var roleService = new RoleService(context);

                roleService.Create(roleAdmin);

                var addedRole = context.Roles.Last();

                int id = addedRole.Id;

                Role newRole = new Role
                {
                    Name        = "Admiiiin",
                    Description = "admiiin"
                };

                context.Entry(addedRole).State = EntityState.Detached;

                var updatedRole = roleService.Upsert(id, newRole);

                var lastRole = context.Roles.Last();

                Assert.AreEqual(lastRole.Name, newRole.Name);
            }
        }
Esempio n. 7
0
        public void ValidRegisterShouldCreateNewUser()
        {
            var options = new DbContextOptionsBuilder <MoviesDbContext>()
                          .UseInMemoryDatabase(databaseName: nameof(ValidRegisterShouldCreateNewUser))// "ValidRegisterShouldCreateANewUser")
                          .Options;

            using (var context = new MoviesDbContext(options))
            {
                var validator    = new RegisterValidator();
                var usersService = new UsersService(context, validator, null, config);
                var added        = new ExamenNet.ViewModels.RegisterPostModel
                {
                    FirstName = "firstName1",
                    LastName  = "lastName1",
                    UserName  = "******",
                    Email     = "*****@*****.**",
                    Password  = "******"
                };

                var result = usersService.Register(added);

                Assert.IsNull(result);
                Assert.AreEqual(added.UserName, context.Users.FirstOrDefault(u => u.Id == 1).Username);
                Assert.AreEqual(1, context.UserUserRoles.FirstOrDefault(uur => uur.Id == 1).UserId);
            }
        }
 private void SeedDummyData()
 {
     using (var moviesDbContext = new MoviesDbContext(_dbContextOptions))
     {
         for (var i = 0; i < moviesCount; i++)
         {
             moviesDbContext.Movies.Add(new Movie
             {
                 Title      = $"Movie title {i}",
                 Year       = "1975",
                 Rated      = "R",
                 Released   = "19 Nov 1975",
                 Runtime    = "133 min",
                 Genre      = "Drama",
                 Director   = "Milos Forman",
                 Writer     = "Lawrence Hauben (screenplay), Bo Goldman (screenplay), Ken Kesey (based on the novel by), Dale Wasserman (the play version= \"One Flew Over the Cuckoo's Nest\" by)",
                 Actors     = "Michael Berryman, Peter Brocco, Dean R. Brooks, Alonzo Brown",
                 Plot       = "A criminal pleads insanity and is admitted to a mental institution, where he rebels against the oppressive nurse and rallies up the scared patients.",
                 Language   = "English, Spanish",
                 Country    = "USA, France",
                 Awards     = "Won 5 Oscars. Another 30 wins & 15 nominations.",
                 Poster     = "https=//m.media-amazon.com/images/M/MV5BZjA0OWVhOTAtYWQxNi00YzNhLWI4ZjYtNjFjZTEyYjJlNDVlL2ltYWdlL2ltYWdlXkEyXkFqcGdeQXVyMTQxNzMzNDI@._V1_SX300.jpg",
                 ImdbRating = "8.7",
                 ImdbID     = $"tt0073486-{i}"
             });
         }
         moviesDbContext.SaveChanges();
     }
 }
Esempio n. 9
0
        public void UpsertShouldModifyTheGivenUserRole()
        {
            var options = new DbContextOptionsBuilder <MoviesDbContext>()
                          .UseInMemoryDatabase(databaseName: nameof(UpsertShouldModifyTheGivenUserRole))
                          .EnableSensitiveDataLogging()
                          .Options;

            using (var context = new MoviesDbContext(options))
            {
                var userRoleService = new UserRoleService(context);
                var toAdd           = new UserRolePostModel()
                {
                    Name        = "Newcomer",
                    Description = "..."
                };

                var added = userRoleService.Create(toAdd);

                var update = new UserRolePostModel()
                {
                    Name = "NewRole"
                };

                var toUp = userRoleService.Create(update);
                Assert.IsNotNull(toUp);
                Assert.AreEqual(added.Name, added.Name);
                Assert.AreEqual(added.Name, added.Name);
            }
        }
Esempio n. 10
0
        public void AuthenticateShouldLogTheRegisteredUser()
        {
            var options = new DbContextOptionsBuilder <MoviesDbContext>()
                          .UseInMemoryDatabase(databaseName: nameof(AuthenticateShouldLogTheRegisteredUser))
                          .Options;

            using (var context = new MoviesDbContext(options))
            {
                var usersService = new UsersService(context, config);
                var added        = new Lab3Movie.ViewModels.RegisterPostModel
                {
                    FirstName = "firstName1",
                    LastName  = "lastName1",
                    UserName  = "******",
                    Email     = "*****@*****.**",
                    Password  = "******"
                };
                var result = usersService.Register(added);

                var authenticated = new Lab3Movie.ViewModels.LoginPostModel
                {
                    Username = "******",
                    Password = "******"
                };
                var authresult = usersService.Authenticate(added.UserName, added.Password);

                Assert.IsNotNull(authresult);
                Assert.AreEqual(1, authresult.Id);
                Assert.AreEqual(authenticated.Username, authresult.Username);
            }
        }
Esempio n. 11
0
        private void CreateUser(MoviesDbContext context, string email, string fullName, string password)
        {
            // Create user manager
            var userManager = new UserManager <ApplicationUser>(
                new UserStore <ApplicationUser>(context));

            // Set user manager password validator
            userManager.PasswordValidator = new PasswordValidator
            {
                RequiredLength          = 1,
                RequireDigit            = false,
                RequireLowercase        = false,
                RequireUppercase        = false,
                RequireNonLetterOrDigit = false,
            };

            // Create user object
            var admin = new ApplicationUser
            {
                UserName = email,
                FullName = fullName,
                Email    = email,
            };

            // create user
            var result = userManager.Create(admin, password);

            // validate result
            if (!result.Succeeded)
            {
                throw new Exception(string.Join(";", result.Errors));
            }
        }
        public void GetAllShouldReturnAllComments()
        {
            var options = new DbContextOptionsBuilder <MoviesDbContext>()
                          .UseInMemoryDatabase(databaseName: nameof(GetAllShouldReturnAllComments))
                          .Options;

            using (var context = new MoviesDbContext(options))
            {
                var movieService   = new MovieService(context);
                var userService    = new UserService(context, config, registerValidator, roleValidator);
                var commentService = new CommentService(context);

                userService.Register(user);

                var addedUser = context.Users.Last();

                movieService.Create(movie, addedUser);

                var addedMovie = context.Movies.Last();

                int allComments = commentService.GetAll().Count();

                Assert.AreEqual(3, allComments);
            }
        }
Esempio n. 13
0
        public ActionResult Save(Movie movieBm)
        {
            bool status = false;

            if (ModelState.IsValid)
            {
                using (MoviesDbContext ctx = new MoviesDbContext())
                {
                    if (movieBm.Id > 0)
                    {
                        // Edit
                        Movie movie = ctx.Movies.FirstOrDefault(m => m.Id == movieBm.Id);
                        if (movie != null)
                        {
                            movie.Title        = movieBm.Title;
                            movie.DirectorName = movieBm.DirectorName;
                            movie.ReleaseDate  = movieBm.ReleaseDate;
                        }
                    }
                    else
                    {
                        // Save
                        ctx.Movies.Add(movieBm);
                    }
                    ctx.SaveChanges();
                    status = true;
                }
            }

            return(new JsonResult {
                Data = new { status = status }
            });
        }
        public void GetByIdShouldReturnAComment()
        {
            var options = new DbContextOptionsBuilder <MoviesDbContext>()
                          .UseInMemoryDatabase(databaseName: nameof(GetByIdShouldReturnAComment))
                          .Options;

            using (var context = new MoviesDbContext(options))
            {
                var movieService   = new MovieService(context);
                var userService    = new UserService(context, config, registerValidator, roleValidator);
                var commentService = new CommentService(context);

                userService.Register(user);

                var addedUser = context.Users.Last();

                movieService.Create(movie, addedUser);

                var addedMovie = context.Movies.Last();

                var lastComment = addedMovie.Comments.Last();

                int id = lastComment.Id;

                var commentById = commentService.GetById(id);

                Assert.AreEqual(commentById.Text, "bda");
            }
        }
Esempio n. 15
0
        public void Configure(IApplicationBuilder app,
                              IHostingEnvironment env,
                              MoviesDbContext moviesDbContext)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();

                app.UseWebpackDevMiddleware(new WebpackDevMiddlewareOptions
                {
                    HotModuleReplacement = true
                });
            }
            app.UseStaticFiles();
            moviesDbContext.CreateSeedData();

            app.UseMvc();

            // app.Run(async (context) =>
            // {
            //     await context
            //               .Response
            //               .WriteAsync("Hello World!");
            // });
        }
Esempio n. 16
0
        public void GetByIdShouldReturnAnValidUser()
        {
            var options = new DbContextOptionsBuilder <MoviesDbContext>()
                          .UseInMemoryDatabase(databaseName: nameof(GetByIdShouldReturnAnValidUser))
                          .Options;

            using (var context = new MoviesDbContext(options))
            {
                var validator    = new RegisterValidator();
                var usersService = new UsersService(context, validator, null, config);
                var added1       = new Lab3Movie.ViewModels.RegisterPostModel
                {
                    FirstName = "firstName1",
                    LastName  = "firstName1",
                    UserName  = "******",
                    Email     = "*****@*****.**",
                    Password  = "******"
                };

                usersService.Register(added1);
                var userById = usersService.GetById(1);

                Assert.NotNull(userById);
                Assert.AreEqual("firstName1", userById.FirstName);
            }
        }
Esempio n. 17
0
 internal int PerformIndexing(IElasticClient client, MoviesDbContext db, Guid id)
 {
     return(PerformIndexing(client, db, new List <Guid>()
     {
         id
     }));
 }
Esempio n. 18
0
        public void GetAllShouldReturnCorrectNumberOfPages()
        {
            var options = new DbContextOptionsBuilder <MoviesDbContext>()
                          .UseInMemoryDatabase(databaseName: nameof(GetAllShouldReturnCorrectNumberOfPages))
                          .Options;

            using (var context = new MoviesDbContext(options))
            {
                var movieService = new MovieService(context);
                var addedTask    = movieService.Create(new Lab3Movie.ViewModels.MoviePostModel
                {
                    Title             = "movie 1",
                    Description       = "agfas",
                    Genre             = "comedy",
                    DurationInMinutes = 100,
                    YearOfRelease     = 2019,
                    Director          = "director1",
                    Rating            = 10,
                    Watched           = "yes",
                    DateAdded         = new DateTime(),
                    Comments          = new List <Comment>()
                    {
                        new Comment
                        {
                            Text      = "text",
                            Important = true,
                            Owner     = null
                        }
                    },
                }, null);

                var allMovies = movieService.GetAll(1);
                Assert.NotNull(allMovies);
            }
        }
        public MoviesController CreateController(MoviesDbContext context)
        {
            var repository = new MoviesRepository(context);
            var controller = new MoviesController(repository);

            return(controller);
        }
Esempio n. 20
0
        public void DeleteMovieTest()
        {
            var options = new DbContextOptionsBuilder <MoviesDbContext>()
                          .UseInMemoryDatabase(databaseName: nameof(DeleteMovieTest))
                          .Options;

            using (var context = new MoviesDbContext(options))
            {
                var movieService = new MovieService(context);
                var addedMovie   = movieService.Create(new Lab3Movie.ViewModels.MoviePostModel
                {
                    Title             = "movie 1",
                    Description       = "agfas",
                    Genre             = "comedy",
                    DurationInMinutes = 100,
                    YearOfRelease     = 2019,
                    Director          = "director1",
                    Rating            = 10,
                    Watched           = "yes",
                    DateAdded         = new DateTime(),
                    Comments          = new List <Comment>()
                    {
                        new Comment
                        {
                            Text      = "text",
                            Important = true,
                            Owner     = null
                        }
                    },
                }, null);

                var movieDeleted = movieService.Delete(addedMovie.Id);
                Assert.IsNotNull(movieDeleted);
            }
        }
Esempio n. 21
0
        public void DeleteShouldDeleteAndReturnTheDeletedUserRole()
        {
            var options = new DbContextOptionsBuilder <MoviesDbContext>()
                          .UseInMemoryDatabase(databaseName: nameof(DeleteShouldDeleteAndReturnTheDeletedUserRole))
                          .Options;

            using (var context = new MoviesDbContext(options))
            {
                var userRoleService = new UserRoleService(context);
                var addUserRole     = new UserRolePostModel()
                {
                    Name        = "Newcomer",
                    Description = "..."
                };


                var actual               = userRoleService.Create(addUserRole);
                var afterDelete          = userRoleService.Delete(actual.Id);
                int numberOfUserRoleInDb = context.UserRoles.CountAsync().Result;
                var resultUR             = context.UserRoles.Find(actual.Id);


                Assert.IsNotNull(afterDelete);
                Assert.IsNull(resultUR);
                Assert.AreEqual(0, numberOfUserRoleInDb);
            }
        }
Esempio n. 22
0
        public ErrorsCollection Validate(UserUserRolePostModel userUserRolePosModel, MoviesDbContext context)
        {
            ErrorsCollection errorsCollection = new ErrorsCollection {
                Entity = nameof(UserUserRolePostModel)
            };


            List <string> userRoles = context

                                      .UserRoles
                                      .Select(userRole => userRole.Name)
                                      .ToList();


            if (!userRoles.Contains(userUserRolePosModel.UserRoleName))
            {
                errorsCollection.ErrorMessages.Add($"The UserRole {userUserRolePosModel.UserRoleName} does not exist!");
            }

            if (errorsCollection.ErrorMessages.Count > 0)
            {
                return(errorsCollection);
            }
            return(null);
        }
Esempio n. 23
0
        public void ValidRegisterShouldCreateANewUser()
        {
            // se ruleaza in Package Manager Console pt InMEmoryDatabases  :
            // Install -Package Microsoft.EntityFrameworkCore.InMemory

            var options = new DbContextOptionsBuilder <MoviesDbContext>()
                          .UseInMemoryDatabase(databaseName: nameof(ValidRegisterShouldCreateANewUser))// "ValidRegisterShouldCreateANewUser")
                          .Options;

            using (var context = new MoviesDbContext(options))
            {
                var usersService = new UsersService(context, config);
                var added        = new WebApplication3.ViewModels.RegisterPostModel
                {
                    Email     = "*****@*****.**",
                    FirstName = "corina",
                    LastName  = "sofron",
                    Password  = "******",
                    Username  = "******"
                };
                var result = usersService.Register(added);

                Assert.IsNotNull(result);
                Assert.AreEqual(added.Username, result.UserName);
            }
        }
Esempio n. 24
0
        public void CreateShouldAddAndReturnTheCreatedMovie()
        {
            var options = new DbContextOptionsBuilder <MoviesDbContext>()
                          .UseInMemoryDatabase(databaseName: nameof(CreateShouldAddAndReturnTheCreatedMovie))
                          .Options;

            using (var context = new MoviesDbContext(options))
            {
                var movieService = new MovieService(context);
                var added        = movieService.Create(new WebApplication3.ViewModels.MoviePostModel

                {
                    Title        = "Titanic",
                    Duration     = 100,
                    Genre        = "Thriller",
                    WatchedState = "Yes",
                    DateAdded    = DateTime.Parse("2019-06-15T00:00:00"),
                    DateClosed   = null,

                    Comments = new List <Comment>()
                    {
                        new Comment
                        {
                            Important = true,
                            Text      = "A nice movie",
                        }
                    },
                }, null);


                Assert.IsNotNull(added);
                Assert.AreEqual("Titanic", added.Title);
                Assert.AreNotEqual("Mask", added.Title);
            }
        }
Esempio n. 25
0
        public IReadOnlyCollection <Movie> GetMoviesByUserRating(Guid userId, int take)
        {
            using (MoviesDbContext context = _dbContextFactory())
            {
                var moviesWithRatings = context.Ratings
                                        .Include(a => a.Movie)
                                        .ThenInclude(a => a.Ratings)
                                        .Where(a => a.User.Id == userId)
                                        .OrderByDescending(a => a.Rating)
                                        .ThenBy(a => a.Movie.Title)
                                        .Take(take)
                                        .Select(a => new { a.Movie, a.Movie.Ratings });

                return(moviesWithRatings.Select(a =>
                                                new Movie
                {
                    Id = a.Movie.Id,
                    Genre = a.Movie.Genre,
                    RunningTime = a.Movie.RunningTime,
                    Title = a.Movie.Title,
                    YearOfRelease = a.Movie.YearOfRelease,
                    AverageRating = a.Ratings == null || !a.Ratings.Any()
                            ? null
                            : (decimal?)a.Ratings.Average(b => b.Rating).RoundToNearestPointFive(),
                }).ToList());
            }
        }
Esempio n. 26
0
        public void InvalidAuthentificationShouldNotAuthenticateUserWithInvalidPassword()
        {
            var options = new DbContextOptionsBuilder <MoviesDbContext>()
                          .UseInMemoryDatabase(databaseName: nameof(InvalidAuthentificationShouldNotAuthenticateUserWithInvalidPassword))
                          .Options;

            using (var context = new MoviesDbContext(options))
            {
                var userService = new UserService(context, config);

                var addedUser = new Lab2.ViewModels.RegisterPostModel
                {
                    Email     = "[email protected]",
                    FirstName = "asdfg",
                    LastName  = "asdsdfgfgh",
                    Password  = "******",
                    Username  = "******"
                };

                var addResult = userService.Register(addedUser);

                Assert.IsNotNull(addResult);
                Assert.AreEqual(addedUser.Username, addResult.Username);

                var authentificate = new Lab2.ViewModels.UserGetModel
                {
                    Email    = "[email protected]",
                    Username = "******"
                };

                var result = userService.Authenticate(addedUser.Username, "11111111");

                Assert.AreEqual(null, result);
            }
        }
Esempio n. 27
0
        public void DeleteShouldEmptyTheDb()
        {
            var options = new DbContextOptionsBuilder <MoviesDbContext>()
                          .UseInMemoryDatabase(databaseName: nameof(DeleteShouldEmptyTheDb))
                          .Options;

            using (var context = new MoviesDbContext(options))
            {
                var validator    = new RegisterValidator();
                var usersService = new UsersService(context, validator, null, config);
                var added1       = new ExamenNet.ViewModels.RegisterPostModel
                {
                    FirstName = "firstName1",
                    LastName  = "firstName1",
                    UserName  = "******",
                    Email     = "*****@*****.**",
                    Password  = "******"
                };

                var userCreated = usersService.Create(added1);

                Assert.IsNull(userCreated);
                Assert.AreEqual(1, usersService.GetAll().Count());

                var userDeleted = usersService.Delete(1);

                Assert.NotNull(userDeleted);
                Assert.AreEqual(0, usersService.GetAll().Count());
            }
        }
Esempio n. 28
0
        public void ValidRegisterShouldCerateANewUser()
        {
            var options = new DbContextOptionsBuilder <MoviesDbContext>()
                          .UseInMemoryDatabase(databaseName: nameof(ValidRegisterShouldCerateANewUser))
                          .Options;

            using (var context = new MoviesDbContext(options))
            {
                var userService = new UserService(context, config);

                var added = new Lab2.ViewModels.RegisterPostModel
                {
                    Email     = "[email protected]",
                    FirstName = "asdf",
                    LastName  = "asdfgh",
                    Password  = "******",
                    Username  = "******"
                };

                var result = userService.Register(added);

                Assert.IsNotNull(result);
                Assert.AreEqual(added.Username, result.Username);
            }
        }
        public IUnitOfWork Create()
        {
            var dbContext = new MoviesDbContext(_builder.Options);
            var uow       = new UnitOfWork(dbContext);

            return(uow);
        }
Esempio n. 30
0
 public UserService(MoviesDbContext context, IOptions <AppSettings> appSettings, IRegisterValidator registerValidator, IRoleValidator roleValidator)
 {
     this.context           = context;
     this.appSettings       = appSettings.Value;
     this.registerValidator = registerValidator;
     this.roleValidator     = roleValidator;
 }
Esempio n. 31
0
        public void SaveMovie(MoviesDbContext context, Movie movie)
        {
            if (movie.Id <= 0)
            {
                context.Entry(movie).State = EntityState.Added;
            }
            else
            {
                context.Entry(movie).State = EntityState.Modified;
            }

            context.SaveChanges();
        }
Esempio n. 32
0
 public void DeleteMovie(MoviesDbContext context, Movie movie)
 {
     context.Entry(movie).State = EntityState.Deleted;
     context.SaveChanges();
 }
Esempio n. 33
0
 public Movie GetMovie(MoviesDbContext context, int id)
 {
     return context.Movies.FirstOrDefault(x => x.Id.Equals(id));
 }
 public HomeController()
 {
     this.dbContext = new MoviesDbContext();
 }
Esempio n. 35
0
 public ActorsController()
 {
     this.dbContext = new MoviesDbContext();
 }