public CustomerDto(Customer customer) { this.Id = customer.Id; this.Firstname = customer.Firstname; this.Lastname = customer.Lastname; this.Email = customer.Email; }
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; }