Ejemplo n.º 1
0
        public ActionResult Register(CustomerRegistrationViewModel CustomerRegistrationViewModel)
        {
            Account customer = new Account()
            {
                Name     = CustomerRegistrationViewModel.Name,
                Email    = CustomerRegistrationViewModel.Email,
                Password = CustomerRegistrationViewModel.Password
            };

            if (ModelState.IsValid)
            {
                if (CustomerRegistrationViewModel.Password == CustomerRegistrationViewModel.PasswordCheck)
                {
                    if (CustomerRepo.AddCustomer(customer))
                    {
                        //string naam = customer.Name;

                        //var fromAddress = new MailAddress("*****@*****.**", "BioscoopB3");
                        //var toAddress = new MailAddress(customer.Email, "To Name");
                        //const string fromPassword = "******";
                        //const string subject = "Aanmelding nieuwsbrief";
                        //string body = "Beste " + naam + ",<br/><br/>U heeft zich succesvol geabboneerd op onze nieuwsbrief. <br/><br/>Mvg,<br/><br/> BioscoopB3";

                        //var smtp = new SmtpClient
                        //{
                        //    Host = "smtp.gmail.com",
                        //    Port = 587,
                        //    EnableSsl = true,
                        //    DeliveryMethod = SmtpDeliveryMethod.Network,
                        //    UseDefaultCredentials = false,
                        //    Credentials = new NetworkCredential(fromAddress.Address, fromPassword)
                        //};
                        //using (var message = new MailMessage(fromAddress, toAddress)
                        //{
                        //    Subject = subject,
                        //    Body = body
                        //})
                        //{
                        //    message.IsBodyHtml = true;
                        //    smtp.Send(message);
                        //}
                        return(View("Thanks", customer));
                    }
                    else
                    {
                        return(View("AlreadyRegistered", customer));
                    }
                }
                else
                {
                    ViewBag.PasswordError = "Wachtwoorden waren niet gelijk";
                    return(View());
                }
            }
            else
            {
                // there is a validation error
                return(View());
            }
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> Post([FromBody] CustomerRegistrationViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var userIdentity = new ApplicationUser()
            {
                UserName = model.Email,
                Email    = model.Email
            };

            var result = await _userManager.CreateAsync(userIdentity, model.Password);

            if (!result.Succeeded)
            {
                return(new BadRequestObjectResult(Errors.AddErrorsToModelState(result, ModelState)));
            }

            await _context.Customers.AddAsync(new Customer
            {
                IdentityId  = userIdentity.Id,
                FirstName   = model.FirstName,
                LastName    = model.LastName,
                CompanyName = model.CompanyName,
                Address     = model.Address
            });

            await _context.SaveChangesAsync();

            return(new OkObjectResult("Account created"));
        }
Ejemplo n.º 3
0
        public async Task <IActionResult> Post([FromBody] CustomerRegistrationViewModel model)
        {
            _logger.LogInformation("Post");
            try
            {
                if (!ModelState.IsValid)
                {
                    return(BadRequest(ModelState));
                }

                var userIdentity = _mapper.Map <AppUser>(model);
                var result       = await _userManager.CreateAsync(userIdentity, model.Password);

                if (!result.Succeeded)
                {
                    return(new BadRequestObjectResult(ModelState.AddErrorsToModelState(result)));
                }
                await _applicationDbContext.AddCustomer(userIdentity.Id);

                return(new OkObjectResult("Account created"));
            }
            catch (Exception e)
            {
                _logger.LogError(e, "Post");
                ModelState.AddErrorToModelState(e);
                return(BadRequest(ModelState));
            }
        }
Ejemplo n.º 4
0
 public CustomerRegistrationControl()
 {
     this.InitializeComponent();
     this.ViewModel = new CustomerRegistrationViewModel();
     // Defer to loaded event to set the mode from markup
     //this.Loaded += delegate { this.ViewModel.ResetRegistrationMode(RegistrationMode); };
     this.ViewModel.PauseCamera  += OnPauseCamera;
     this.ViewModel.ResumeCamera += OnResumeCamera;
 }
        public async Task <RegistrationConfirmationViewModel> Register([FromBody] CustomerRegistrationViewModel customerRegistrationInformation)
        {
            if (!ModelState.IsValid)
            {
                var errorList = (from item in ModelState.Values
                                 from error in item.Errors
                                 select error.ErrorMessage).ToList();

                var response = new HttpResponseMessage(HttpStatusCode.BadRequest);
                response.ReasonPhrase = JsonConvert.SerializeObject(errorList);

                throw new HttpResponseException(response);
            }

            try
            {
                var user = await BusinessOperations.RegisterUser(customerRegistrationInformation.Customer);

                var newCustomer = await BusinessOperations.CreateCustomer(customerRegistrationInformation.Customer);

                user = await BusinessOperations.UpdateUser(user, newCustomer.CompanyProfile.TenantId);

                var order = await BusinessOperations.PlaceOrder(newCustomer.CompanyProfile.TenantId, customerRegistrationInformation.Orders);

                return(await BusinessOperations.GetRegistrationConfirmation(newCustomer, customerRegistrationInformation));
            }
            catch (PartnerException partnerException)
            {
                HttpResponseMessage errorResponse = new HttpResponseMessage();
                errorResponse.ReasonPhrase = partnerException.ServiceErrorPayload.ErrorMessage;

                switch (partnerException.ErrorCategory)
                {
                case PartnerErrorCategory.BadInput:
                    errorResponse.StatusCode = HttpStatusCode.BadRequest;
                    break;

                case PartnerErrorCategory.Unauthorized:
                    errorResponse.StatusCode = HttpStatusCode.Unauthorized;
                    break;

                default:
                    errorResponse.StatusCode = HttpStatusCode.InternalServerError;
                    break;
                }

                throw new HttpResponseException(errorResponse);
            }
            catch (InvalidOperationException userCreateProblem)
            {
                HttpResponseMessage errorResponse = new HttpResponseMessage(HttpStatusCode.InternalServerError);
                errorResponse.ReasonPhrase = userCreateProblem.Message;

                throw new HttpResponseException(errorResponse);
            }
        }
Ejemplo n.º 6
0
        public async Task Post(CustomerRegistrationViewModel mockModel)
        {
            try
            {
                await _context.GetContext();

                var controller = new AccountsController(MockHelper.GetUserManager(new UserStore <AppUser>(_context.Context)), MockHelper.Mapper.Value, _context.Context, MockHelper.MockLogger <AccountsController>());

                var result = await controller.Post(mockModel);

                result.Should().BeOfType <OkObjectResult>().Which.Value.Should().Be("Account created");
            }
            finally
            {
                _context.Close();
            }
        }
Ejemplo n.º 7
0
        public async Task <ActionResult> Register(CustomerRegistrationViewModel model)
        {
            var customer = new ServiceModelsCustomerDTO()
            {
                PersonalId = model.Id,
                Name       = model.Name
            };

            if (service.CreateCustomer(customer) != 0)
            {
                return(View("SuccessfulRegistration"));
            }
            else
            {
                return(View("Error"));
            }
        }
Ejemplo n.º 8
0
        public async Task <IActionResult> Register(CustomerRegistrationViewModel model, string returnUrl = null)
        {
            ViewData["ReturnUrl"] = returnUrl;
            if (ModelState.IsValid && model.Agreement)
            {
                var customer = new Customer()
                {
                    UserName = model.Email,
                    Email    = model.Email
                };

                var result = await userManager.CreateAsync(customer, model.Password);

                if (result.Succeeded)
                {
                    logger.LogInformation("User created a new account with password.");

                    var code = await userManager.GenerateEmailConfirmationTokenAsync(customer);

                    var callBackUrl = Url.EmailConfirmationLink(customer.Id, code, Request.Scheme);
                    await emailSender.SendEmailConfirmationAsync(model.Email, callBackUrl);

                    await signInManager.SignInAsync(customer, isPersistent : false);

                    logger.LogInformation("User created a new account with password.");

                    await userManager.AddToRoleAsync(customer, "User");

                    logger.LogInformation("User was assigned role USER.");

                    await emailSubscriptions.AddAsync(new EmailSubscription()
                    {
                        Email  = model.Email,
                        Status = true
                    });

                    logger.LogInformation("User was added to mail list.");

                    return(RedirectToLocal(returnUrl));
                }

                AddErrors(result);
            }
            return(View(model));
        }
Ejemplo n.º 9
0
        public ActionResult CustomerRegistration(CustomerRegistrationViewModel model)
        {
            if (ModelState.IsValid)
            {
                if (db.Users.Any(x => x.Username == model.Username))
                {
                    ModelState.AddModelError("Username", "Username already exist");
                    return(View(model));
                }
                if (db.Customers.Any(x => x.Email == model.Email))
                {
                    ModelState.AddModelError("Email", "Email already used to register");
                    return(View(model));
                }

                User user = new User()
                {
                    UserID   = Guid.NewGuid(),
                    Username = model.Username,
                    Password = model.Password,
                    Role     = "Customer"
                };
                db.Users.Add(user);
                db.SaveChanges();

                Customer customer = new Customer()
                {
                    CustomerID       = user.UserID,
                    Fname            = model.Fname,
                    Lname            = model.Lname,
                    Email            = model.Email,
                    ContactNum       = model.ContactNum,
                    IcNum            = model.IcNum,
                    Address          = model.Address,
                    DOB              = model.DOB,
                    RegistrationDate = DateTime.Today,
                    Gender           = model.Gender
                };
                db.Customers.Add(customer);
                db.SaveChanges();
                return(RedirectToAction("Login", "Account"));
            }
            return(View(model));
        }
Ejemplo n.º 10
0
        public void CustomerRegistrationViewModelToAppUser(CustomerRegistrationViewModel vm)
        {
            var result = MockHelper.Mapper.Value.Map <AppUser>(vm);

            result.Should().BeOfType <AppUser>();
        }
Ejemplo n.º 11
0
        /// <summary>
        /// Builds a registration confirmation for a new customer.
        /// </summary>
        /// <param name="customer">The customer.</param>
        /// <param name="registrationInformation">The registration confirmation.</param>
        /// <returns>The registration confirmation view model.</returns>
        public static async Task <RegistrationConfirmationViewModel> GetRegistrationConfirmation(Customer customer, CustomerRegistrationViewModel registrationInformation)
        {
            var subscriptions = await partnerOperations.Customers.ById(customer.CompanyProfile.TenantId).Subscriptions.GetAsync();

            List <SubscriptionViewModel> subscriptionViewModels = new List <SubscriptionViewModel>();

            foreach (var subscription in subscriptions.Items)
            {
                var offer = await subscription.Links.Offer.InvokeAsync <Offer>(partnerOperations);

                subscriptionViewModels.Add(new SubscriptionViewModel()
                {
                    FriendlyName = subscription.FriendlyName,
                    Quantity     = subscription.Quantity.ToString(),
                    Price        = GetOfferPrice(offer.Id)
                });
            }

            var user = new ApplicationUser {
                UserName = registrationInformation.Customer.Email, Email = registrationInformation.Customer.Email, CustomerId = customer.CompanyProfile.TenantId
            };
            var result = await HttpContext.Current.GetOwinContext().GetUserManager <ApplicationUserManager>().UpdateAsync(user);

            return(new RegistrationConfirmationViewModel()
            {
                AdvisorId = registrationInformation.Customer.AdvisorId,
                AddressLine1 = customer.BillingProfile.DefaultAddress.AddressLine1,
                AddressLine2 = customer.BillingProfile.DefaultAddress.AddressLine2,
                City = customer.BillingProfile.DefaultAddress.City,
                State = customer.BillingProfile.DefaultAddress.State,
                ZipCode = customer.BillingProfile.DefaultAddress.PostalCode,
                Country = customer.BillingProfile.DefaultAddress.Country,
                Phone = customer.BillingProfile.DefaultAddress.PhoneNumber,
                Language = customer.BillingProfile.Language,
                FirstName = customer.BillingProfile.DefaultAddress.FirstName,
                LastName = customer.BillingProfile.DefaultAddress.LastName,
                CreditCardNumber = "xxxx xxxx xxxx " + registrationInformation.Customer.CreditCardNumber.Substring(11),
                CreditCardExpiry = string.Format("{0}/{1}", registrationInformation.Customer.CreditCardExpiryMonth, registrationInformation.Customer.CreditCardExpiryYear),
                CreditCardType = registrationInformation.Customer.CreditCardType,
                Email = customer.BillingProfile.Email,
                CompanyName = customer.BillingProfile.CompanyName,
                MicrosoftId = customer.CompanyProfile.TenantId,
                UserName = registrationInformation.Customer.Email,
                Subscriptions = subscriptionViewModels,
                Website = registrationInformation.Customer.Website,
                AdminUserAccount = customer.UserCredentials.UserName + "@" + customer.CompanyProfile.Domain
            });
        }