Ejemplo n.º 1
0
        public static User FromDto(UserDto dto)
        {
            var user = new User
            {
                Id = 1,
                CreationDate = dto.CreationDate,
                FirstName = dto.FirstName,
                LastName = dto.LastName,
                Email = dto.Email,
                EnergyUserName = dto.EnergyUserName,
                Phone = dto.Phone,
            };

            foreach (var role in dto.Roles)
            {
                user.UserUserRoleRelation.Add(new UserUserRoleRelation
                {
                    UserId = user.Id,
                    UserRoleId = role.Id
                });
            }

            if (dto.Company != null)
                user.CompanyId = dto.Company.Id;

            return user;
        }
Ejemplo n.º 2
0
        public void TestUserModel()
        {
            var now = DateTime.Now;
            var user = new User
            {
                Id = 1,
                CreationDate = now,
                FirstName = "firstName",
                LastName = "lastName",
                Email = "[email protected]",
                Password = "******",
                Salt = "salt",
                EnergyPassword = "******",
                EnergyUserName = "******",
                Phone = 12345678,
                //Roles = new List<UserRole>() { new UserRole() { Id = 1, Name = "role" } },
                Company = new Company(),
                //AccessToken = "foobar",
            };

            var dto = UserDto.Create(user);

            Assert.AreEqual(user.Id, dto.Id);
            Assert.AreEqual(user.CreationDate, dto.CreationDate);
            Assert.AreEqual(user.FirstName, dto.FirstName);
            Assert.AreEqual(user.LastName, dto.LastName);
            Assert.AreEqual(user.Email, dto.Email);
            Assert.AreEqual(user.EnergyUserName, dto.EnergyUserName);
            Assert.AreEqual(user.Phone, dto.Phone);
            //Assert.AreEqual(user.UserRole.Name, dto.Role.Name);
            //Assert.AreEqual(user.AccessToken, dto.AccessToken);

            // Create user with only required fields
            var simpleUser = new User
            {
                Id = 1,
                CreationDate = now,
                FirstName = "firstName",
                LastName = "lastName",
                Email = "[email protected]",
                Password = "******",
                Salt = "salt",
                //UserRole = new UserRole() { Id = 1, Name = "role" },
            };

            var simpleDto = UserDto.Create(simpleUser);

            Assert.IsNull(simpleDto.Company);
            Assert.IsNull(simpleDto.Phone);
            Assert.IsNull(simpleDto.EnergyUserName);
        }
 /// <summary>
 /// Create a new User object.
 /// </summary>
 /// <param name="id">Initial value of the Id property.</param>
 /// <param name="creationDate">Initial value of the CreationDate property.</param>
 /// <param name="firstName">Initial value of the FirstName property.</param>
 /// <param name="lastName">Initial value of the LastName property.</param>
 /// <param name="email">Initial value of the Email property.</param>
 /// <param name="password">Initial value of the Password property.</param>
 /// <param name="salt">Initial value of the Salt property.</param>
 public static User CreateUser(global::System.Int32 id, global::System.DateTime creationDate, global::System.String firstName, global::System.String lastName, global::System.String email, global::System.String password, global::System.String salt)
 {
     User user = new User();
     user.Id = id;
     user.CreationDate = creationDate;
     user.FirstName = firstName;
     user.LastName = lastName;
     user.Email = email;
     user.Password = password;
     user.Salt = salt;
     return user;
 }
 /// <summary>
 /// Deprecated Method for adding a new object to the User EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToUser(User user)
 {
     base.AddObject("User", user);
 }