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 void Should_map_view_data_to_dto( ) { ICustomerRegistrationView mockView = mockery.DynamicMock <ICustomerRegistrationView>( ); string userName = "******"; string password = "******"; string firstName = "mo"; string lastName = "khan"; string phoneNumber = "(403)6813389"; string city = "calgary"; using (mockery.Record( )) { SetupResult.For(mockView.UserName( )).Return(userName); SetupResult.For(mockView.Password( )).Return(password); SetupResult.For(mockView.FirstName( )).Return(firstName); SetupResult.For(mockView.LastName( )).Return(lastName); SetupResult.For(mockView.PhoneNumber( )).Return(phoneNumber); SetupResult.For(mockView.City( )).Return(city); } using (mockery.Playback( )) { RegisterCustomerDTO mappedDTO = CreateSUT( ).MapFrom(mockView); Assert.AreEqual(mappedDTO.UserName, userName); Assert.AreEqual(mappedDTO.Password, password); Assert.AreEqual(mappedDTO.FirstName, firstName); Assert.AreEqual(mappedDTO.LastName, lastName); Assert.AreEqual(mappedDTO.Phone, phoneNumber); Assert.AreEqual(mappedDTO.City, city); } }
public IEnumerable <DisplayResponseLineDTO> RegisterNew(RegisterCustomerDTO customer) { if (null == _customers.FindBy(customer.UserName)) { ICustomer newCustomer = _customers.NewCustomer( ); newCustomer.RegisterAccount(customer.UserName, customer.Password, customer.FirstName, customer.LastName, customer.Phone, customer.City); if (!newCustomer.Registration( ).IsValid( )) { return(_mapper.MapFrom(newCustomer.Registration( ).BrokenRules( ))); } else { _customers.Save(newCustomer); return(new DisplayResponseLines("Success!")); } } else { return (new DisplayResponseLines( string.Format("The username {0} is already taken. Please try another!", customer.UserName))); } }
public IActionResult UserRegister(UpdateCustomerVM registerCustomer) { if (!ModelState.IsValid) { ShowToaster("Please fill required fields", ToasterLevel.Danger); return(RedirectToAction("Profile", new { customerId = registerCustomer.Id })); } ViewBag.Class = "inner-page"; var config = new MapperConfiguration(cfg => cfg.CreateMap <UpdateCustomerVM, RegisterCustomerDTO>()); var mapper = new Mapper(config); RegisterCustomerDTO dto = mapper.DefaultContext.Mapper.Map <RegisterCustomerDTO>(registerCustomer); var customer = _userService.UpdateCustomer(dto); if (customer != null) { TempData["isLogin"] = 1; TempData["uid"] = customer.Id; TempData["uname"] = customer.Name; ShowToaster("Profile updated successfully", ToasterLevel.Success); return(RedirectToAction("Profile", new { customerId = registerCustomer.Id })); } else { ShowToaster("Profile not updated", ToasterLevel.Danger); return(RedirectToAction("Profile", new { customerId = registerCustomer.Id })); } }
public void Should_leverage_repository_to_create_a_new_customer() { string username = "******"; string password = "******"; string firstName = "mo"; string lastName = "khan"; string phoneNumber = "4036813389"; string city = "calgary"; RegisterCustomerDTO customerDTO = new RegisterCustomerDTO(username, password, firstName, lastName, phoneNumber, city); ICustomer customer = _mockery.DynamicMock <ICustomer>( ); IRegistration registration = _mockery.DynamicMock <IRegistration>( ); using (_mockery.Record( )) { SetupResult.For(customer.Registration( )).Return(registration); SetupResult.For(registration.IsValid( )).Return(true); Expect.Call(_mockCustomerRepository.NewCustomer( )).Return(customer); customer.RegisterAccount(username, password, firstName, lastName, phoneNumber, city); } using (_mockery.Playback( )) { ListFactory.From(CreateSUT( ).RegisterNew(customerDTO)); } }
public void Should_leverage_task_to_submit_new_registration_information( ) { RegisterCustomerDTO customerRegistrationDTO = ObjectMother.CustomerRegistrationDTO( ); using (mockery.Record( )) { SetupResult.For(mockMapper.MapFrom(mockView)).Return(customerRegistrationDTO); Expect.Call(mockTask.RegisterNew(customerRegistrationDTO)).Return(null); } using (mockery.Playback( )) { CreateSUT( ).RegisterCustomer( ); } }
public Customer UpdateCustomer(RegisterCustomerDTO dto) { if (dto.Id != 0) { var customer = dBContext.Customers.FirstOrDefault(x => x.Id.Equals(dto.Id)); customer.Address = dto.Address; customer.ContactNumber = dto.Contact; customer.Password = dto.Password ?? customer.Password; customer.Name = dto.UserName; customer.CountryId = dto.CountryId; customer.StateId = dto.StateId; customer.Username = dto.UserName; customer.PinCode = dto.Pincode; dBContext.SaveChanges(); return(customer); } else { return(null); } }
public Customer RegisterCustomer(RegisterCustomerDTO dto) { if (!dBContext.Customers.Any(x => x.EmailId.Equals(dto.EmailId))) { var customer = new Customer() { EmailId = dto.EmailId, Address = dto.Address, ContactNumber = dto.Contact, Password = dto.Password, Name = dto.UserName, CountryId = dto.CountryId, StateId = dto.StateId, Username = dto.UserName, PinCode = dto.Pincode, IsEmailVerified = false }; dBContext.Customers.Add(customer); Random generator = new Random(); String code = generator.Next(0, 999999).ToString("D6"); dBContext.EmailVerification.Add(new EmailVerification() { Code = code, Email = dto.EmailId }); dBContext.SaveChanges(); var link = "https://localhost:44397/Account/VerifyEmail?email=" + dto.EmailId + "&code=" + code; if (_emailSenderService != null) { _emailSenderService.SendEmail(dto.EmailId, dto.UserName, "Your are register successfully", link, "https://pbs.twimg.com/media/Ed0u4lSVoAAcPVN?format=png&name=small"); } return(customer); } else { return(null); } }
public IEnumerable <DisplayResponseLineDTO> RegisterNew(RegisterCustomerDTO customer) { return(_underlyingTask.RegisterNew(customer)); }