public RegisterViewModel(User user, CustomerProfile profile)
 {
     Email = user.Email;
         Phone = user.Phone;
         Password = user.Password;
         FirstName = profile.FirstName;
         LastName = profile.LastName;
         StreetName = profile.Address.StreetName;
         StreetNumber = profile.Address.StreetNumber;
         City = profile.Address.City;
         ZipCode = profile.Address.ZipCode;
 }
        public ActionResult Register(RegisterViewModel model)
        {
            if (ModelState.IsValid)
            {
                Role role = _facade.Roles.GetOne(r => r.Name == "user");
                User user = new User {Email = model.Email,Password = model.Password,
                    Phone = model.Phone,Role = role};

                _facade.Users.Create(user);
                _facade.Save();

                User userWithId = _facade.Users.GetOne(u => u.Email ==user.Email && u.Password == user.Password
                                    && u.Phone == user.Phone && u.RoleId == role.Id );
                if (userWithId.Id != 0)
                {
                    Address address = new Address
                    {
                        City = model.City,
                        StreetName = model.StreetName,
                        StreetNumber = model.StreetNumber,
                        ZipCode = model.ZipCode
                    };
                    CustomerProfile customer = new CustomerProfile
                    {
                        Address = address,
                        FirstName = model.FirstName,
                        LastName = model.LastName,
                        Id = userWithId.Id
                    };
                    HttpResponseMessage response = serviceFactory.CustomersGateway.CreateOne(customer);
                    if (response.StatusCode == HttpStatusCode.Created)
                    {
                        return RedirectToAction("Login");
                    }
                    _facade.Users.Delete(userWithId);
                    _facade.Save();
                }
            }

            // If we got this far, something failed, redisplay form
            return View(model);
        }