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 CustomerRegistrationResponseDto TryToRegister(CustomerRegistrationRequestDto dto)
        {            
            if(uow.Users.GetAll().Where(x=>x.Username == dto.Email).FirstOrDefault() != null)
                throw new System.Exception("Invalid Email Address");

            var user = new User()
            {
                Username = dto.Email,
                Firstname = dto.Firstname,
                Lastname = dto.Lastname,
                Password = encryptionService.TransformPassword(dto.Password),
            };
            
            var account = new Account()
            {
                Firstname = dto.Firstname,
                Lastname = dto.Lastname,
                Email = dto.Email,
                AccountType = AccountType.Customer,
                User = user,
                AccountStatus = AccountStatus.Free
            };

            var profile = new Profile()
            {
                Name = string.Format("{0} {1}",dto.Firstname, dto.Lastname),
                Account = account,
                ProfileType = ProfileType.Customer,
                IsPersonalized = true,
                IsApproved = true,                
            };

            var customer = new Customer()
            {
                Firstname = dto.Firstname,
                Lastname = dto.Lastname,
                Email = dto.Email,
                Profile = profile
            };
            
            user.Accounts.Add(account);
            account.Profiles.Add(profile);

            uow.Users.Add(user);
            uow.Accounts.Add(account);
            uow.Customers.Add(customer);
            uow.SaveChanges();

            var response = new CustomerRegistrationResponseDto()
            {
                Firstname = customer.Firstname,
                Lastname = customer.Lastname,
                Id = customer.Id
            };

            return response;
        }
示例#3
0
 public UserDto(User user)
 {
     if (user != null)
     {
         this.Id = user.Id;
         this.Username = user.Username;
         this.Firstname = user.Firstname;
         this.Lastname = user.Lastname;
         this.EmailAddress = user.EmailAddress;
         this.Roles = user.Roles.Where(x => !x.IsDeleted).Select(x => new RoleDto(x)).ToList();
         this.Groups = user.Groups.Where(x => !x.IsDeleted).Select(x => new GroupDto(x)).ToList();
     }
 }
 public Session GetSession(User user)
 {
     return uow.Sessions.GetAll().Where(x => x.UserId == user.Id).FirstOrDefault();
 }
 public TokenDto StartSession(User user)
 {
     return StartSession(user.Id);
 }
        public void SignOut(User user)
        {

        }