Ejemplo n.º 1
0
        public static User ToUser(UserPostModel userModel)
        {
            //UserRole rol = Lab3.Models.UserRole.Regular;

            //if (userModel.UserRole == "UserManager")
            //{
            //    rol = Lab3.Models.UserRole.UserManager;
            //}
            //else if (userModel.UserRole == "Admin")
            //{
            //    rol = Lab3.Models.UserRole.Admin;
            //}

            return(new User
            {
                FirstName = userModel.FirstName,
                LastName = userModel.LastName,
                Username = userModel.UserName,
                Email = userModel.Email,
                Password = ComputeSha256Hash(userModel.Password)
            });
        }
Ejemplo n.º 2
0
        public static User ToUser(UserPostModel userModel)
        {
            UserRole rol = Lab3Movie.Models.UserRole.Regular;

            if (userModel.UserRole == "UserManager")
            {
                rol = Lab3Movie.Models.UserRole.UserManager;
            }
            else if (userModel.UserRole == "Admin")
            {
                rol = Lab3Movie.Models.UserRole.Admin;
            }

            return(new User
            {
                FirstName = userModel.FirstName,
                LastName = userModel.LastName,
                Username = userModel.UserName,
                Email = userModel.Email,
                Password = userModel.Password,
                UserRole = rol
            });
        }
Ejemplo n.º 3
0
        public void UpsertShouldModifyFildsValues()
        {
            var options = new DbContextOptionsBuilder <MoviesDbContext>()
                          .UseInMemoryDatabase(databaseName: nameof(UpsertShouldModifyFildsValues))
                          .Options;

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

                usersService.Create(added22);

                var updated = new Lab3Movie.ViewModels.UserPostModel
                {
                    FirstName = "Alin",
                    LastName  = "Popescu",
                    UserName  = "******",
                    Email     = "*****@*****.**",
                    Password  = "******"
                };

                var userUpdated = usersService.Upsert(1, updated);

                Assert.NotNull(userUpdated);
                Assert.AreEqual("Alin", userUpdated.FirstName);
                Assert.AreEqual("Popescu", userUpdated.LastName);
            }
        }