private User Map(User user, UserDto dto)
        {
            user.Username = dto.Username;
            user.Firstname = dto.Firstname;
            user.Lastname = dto.Lastname;
            user.EmailAddress = dto.EmailAddress;

            user.Roles.Clear();
            user.Groups.Clear();

            // TODO: Implementation Activation workflow
            user.IsActive = true;

            foreach (var role in dto.Roles)
            {
                user.Roles.Add(uow.Roles.GetById(role.Id));
            }

            foreach (var group in dto.Groups)
            {
                user.Groups.Add(uow.Groups.GetById(group.Id));
            }

            return user;
        }
 public void TryToAddUser(UserDto dto)
 {
     var user = Map(new User(), dto);
     user.Password = encryptionService.TransformPassword(dto.Password);
     uow.Users.Add(user);
     uow.SaveChanges();
 }
        public UserDto GetCurrentUser(int sessionId)
        {
            var session = GetSession(sessionId);

            var userId = (int)session.UserId;

            var result = new UserDto(FromCacheOrService<User>(() => uow.Users.GetAll().Where(x => x.Id == userId).Include(x => x.Roles).FirstOrDefault(), string.Format("User By Id: {0}", userId)));

            return result;
        }
        public async Task<UserDto> GetCurrentUser(string username)
        {
            var result = new UserDto();

            await System.Threading.Tasks.Task.Factory.StartNew(() =>
            {
                result = new UserDto(FromCacheOrService<User>(() => uow.Users.GetAll().Where(x => x.Username == username).Include(x => x.Roles).FirstOrDefault(), string.Format("User: {0}", username)));

            });

            return result;
        }
        public void TryToUpdateUser(UserDto dto)
        {
            var user = uow.Users.GetAll()
                .Include(x => x.Roles)
                .Include(x => x.Groups)
                .Where(x => x.Id == dto.Id)
                .Single();

            Map(user, dto);

            uow.Users.Update(user);
            uow.SaveChanges();
        }