public IActionResult UserRegister(RegisterCustomerVM registerCustomer)
        {
            if (!ModelState.IsValid)
            {
                ShowToaster("Please fill required fields", ToasterLevel.Danger);
                return(RedirectToAction("Register", "Account"));
            }
            ViewBag.Class = "inner-page";
            var config = new MapperConfiguration(cfg => cfg.CreateMap <RegisterCustomerVM, RegisterCustomerDTO>());
            var mapper = new Mapper(config);
            RegisterCustomerDTO dto = mapper.DefaultContext.Mapper.Map <RegisterCustomerDTO>(registerCustomer);
            var customer            = _customerService.RegisterCustomer(dto);

            if (customer != null)
            {
                TempData["isLogin"] = 1;
                TempData["uid"]     = customer.Id;
                TempData["uname"]   = customer.Name;
                ShowToaster("User register successfully", ToasterLevel.Success);
                return(RedirectToAction("index", "home"));
            }
            else
            {
                ShowToaster("Email id already exists", ToasterLevel.Danger);
                return(RedirectToAction("Register", "Account"));
            }
        }
        public IActionResult Register()
        {
            RegisterCustomerVM registerCustomerVM = new RegisterCustomerVM();

            ViewBag.Class = "inner-page";
            registerCustomerVM.CountryList = _masterDataService.GetCountries().Select(x => new SelectListItem()
            {
                Text  = x.Name,
                Value = x.Id.ToString()
            }).ToList();
            ViewBag.menu = JsonConvert.SerializeObject(GetCategory());
            return(View(registerCustomerVM));
        }
Example #3
0
        public async Task <IdentityResult> RegisteUserAsync(RegisterCustomerVM model)
        {
            User user = new User
            {
                Name        = model.User.Name,
                Surname     = model.User.Surname,
                Email       = model.User.Email,
                UserName    = model.User.PhoneNumber,
                PhoneNumber = model.User.PhoneNumber
            };


            return(await this.userManager.CreateAsync(user, model.Password));
        }
Example #4
0
        public CustomerRegisteredVM RegisterCustomerRop(RegisterCustomerVM vm)
        {
            var customer = Map(vm);
            var result   = IsValid(customer)
                           .OnSuccess(c => _customerRepository.Save(c))
                           .OnSuccess(c => _mailConfirmer.SendWelcome(c))
                           .OnBoth(cEnd => cEnd.IsSuccess
                    ? new CustomerRegisteredVM {
                CustomerId = cEnd.Value.Id
            }
                    : new CustomerRegisteredVM {
                ErrorMessage = cEnd.Error
            });

            return(result);
        }
Example #5
0
        public CustomerRegisteredVM RegisterCustomerOldSchoolHappyCase(RegisterCustomerVM vm)
        {
            var customer = Map(vm);
            var isValid  = IsValid(customer);

            if (isValid)
            {
                customer = _customerRepository.SaveClassic(customer);
                _mailConfirmer.SendWelcome(customer);
                return(new CustomerRegisteredVM {
                    CustomerId = customer.Id
                });
            }
            return(new CustomerRegisteredVM {
                ErrorMessage = "ups"
            });
        }
        public void Registration_invalid_customer_returns_error_message()
        {
            // Arrange
            var customer = Result.Ok(new Customer {
                Id = 42
            });

            var sut = DefaultSetup(customer);

            var invalidVm = new RegisterCustomerVM {
                Name = ""
            };

            // Act
            var result = sut.RegisterCustomer(invalidVm);

            // Assert
            result.ErrorMessage.Should().Be("Name is empty!");
        }
        public void Registration_valid_customer_returns_correct_id()
        {
            // Arrange
            var customer = Result.Ok(new Customer {
                Id = 42
            });

            var sut = DefaultSetup(customer);

            var validVm = new RegisterCustomerVM {
                Name = "valid"
            };

            // Act
            var result = sut.RegisterCustomer(validVm);

            // Assert
            result.CustomerId.Should().Be(42);
        }
        public void Registration_customer_mail_failure_returns_error_message()
        {
            // Arrange
            var customer = new Customer {
                Id = 42
            };
            var sut = DefaultSetup(customer);

            _mailer.SendWelcomeClassic(Arg.Any <Customer>())
            .Throws(new Exception("mail error"));

            var validVm = new RegisterCustomerVM {
                Name = "valid"
            };

            // Act
            var result = sut.RegisterCustomer(validVm);

            // Assert
            result.ErrorMessage.Should().Be("mail error");
        }
Example #9
0
        public async Task <ActionResult> RegisterCustomer(RegisterCustomerVM model)
        {
            ClaimsIdentity identity = authenticationService.GetClaimsIdentity(model.User);

            if (identity == null)
            {
                ModelState.AddModelError("", "Неправильный логин и (или) пароль");
                return(View(model));
            }

            JwtSecurityToken jwtToken     = authenticationService.GetJWTToken(identity.Claims);
            string           access_token = authenticationService.GetAccessToken(jwtToken);

            IdentityResult userIdentity = await authenticationService.RegisteUserAsync(model);

            if (userIdentity == null)
            {
                ModelState.AddModelError("", "Внутренняя ошибка сервера");
                return(View(model));
            }

            if (!userIdentity.Succeeded)
            {
                ModelState.AddModelError("", "Пользователь уже существует");
                return(View(model));
            }


            // save into cookies
            httpContextAccessor.HttpContext.Response.Cookies.Append(".AspNetCore.Application.Id", access_token,
                                                                    new CookieOptions
            {
                //   MaxAge = TimeSpan.FromMinutes(60)
            }
                                                                    );


            return(RedirectToAction("Index", "Home"));
        }
Example #10
0
        public CustomerRegisteredVM RegisterCustomerOldSchoolWithErrorHandling(RegisterCustomerVM vm)
        {
            var customer = Map(vm);
            var isValid  = IsValid(customer);

            if (isValid)
            {
                try
                {
                    customer = _customerRepository.SaveClassic(customer);
                }
                catch (System.Exception e)
                {
                    return(new CustomerRegisteredVM {
                        ErrorMessage = e.Message
                    });
                }
                try
                {
                    _mailConfirmer.SendWelcomeClassic(customer);
                }
                catch (System.Exception e)
                {
                    return(new CustomerRegisteredVM {
                        ErrorMessage = e.Message
                    });
                }

                // Happy path
                return(new CustomerRegisteredVM {
                    CustomerId = customer.Id
                });
            }

            return(new CustomerRegisteredVM {
                ErrorMessage = "Name is empty!"
            });
        }
        public void Registration_customer_mail_failure_returns_error_message()
        {
            // Arrange
            var customer = Result.Ok(new Customer {
                Id = 42
            });
            var sut = DefaultSetup(customer);

            _mailer.SendWelcome(Arg.Any <Customer>())
            .Returns(Result.Fail <Customer, RopError>(
                         new RopError {
                Message = "mail error"
            }));

            var validVm = new RegisterCustomerVM {
                Name = "valid"
            };

            // Act
            var result = sut.RegisterCustomer(validVm);

            // Assert
            result.ErrorMessage.Should().Be("mail error");
        }
Example #12
0
 public IActionResult RegisterCustomerREST(RegisterCustomerVM model)
 {
     return(Ok());
 }
Example #13
0
 private Customer Map(RegisterCustomerVM vm)
 {
     return(new Customer {
         Name = vm.Name
     });
 }
Example #14
0
 public CustomerRegisteredVM RegisterCustomer(RegisterCustomerVM vm)
 {
     return(RegisterCustomerRop(vm));
 }
Example #15
0
 public CustomerRegisteredVM RegisterCustomer(RegisterCustomerVM vm)
 {
     return(RegisterCustomerOldSchoolHappyCase(vm));
     // return RegisterCustomerOldSchoolWithErrorHandling(vm);
 }