Esempio n. 1
0
        public void DoesFindByNameWorks()
        {
            var options = new DbContextOptionsBuilder <MDManagementDbContext>()
                          .UseInMemoryDatabase(databaseName: "testDb")
                          .Options;

            using (var dbContext = new MDManagementDbContext(options))
            {
                ITownDataService    townService = new TownDataService(dbContext);
                IAddressDataService service     = new AddressDataService(dbContext);

                CreateTownServiceModel createTownServiceModel = new CreateTownServiceModel()
                {
                    Name     = "Pernik",
                    PostCode = 2300
                };

                townService.Create(createTownServiceModel);

                CreateAddressServiceModel model = new CreateAddressServiceModel()
                {
                    AddressText = "new",
                    TownId      = 1
                };

                service.Create(model);

                var result = service.FindByName("new").AddressText;

                Assert.AreEqual(result, dbContext.Addresses.FirstOrDefault().AddressText);
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Creates an address
        /// </summary>
        /// <param name="address">Service model which creastes an address</param>
        public void Create(CreateAddressServiceModel address)
        {
            var addressToAdd = new Address()
            {
                AddressText = address.AddressText,
                TownId      = address.TownId
            };

            data.Addresses.Add(addressToAdd);

            data.SaveChanges();
        }
Esempio n. 3
0
        public async Task <IActionResult> OnPostAsync(string returnUrl = null)
        {
            returnUrl      = returnUrl ?? Url.Content("~/");
            ExternalLogins = (await _signInManager.GetExternalAuthenticationSchemesAsync()).ToList();
            if (ModelState.IsValid)
            {
                //REGISTERING TOWN AND ADDREES
                //TO DO:
                var createTownServiceModel = new CreateTownServiceModel()
                {
                    Name     = Input.Town,
                    PostCode = Input.PostCode
                };

                townDataService.Create(createTownServiceModel);

                var townId = townDataService.FindByName(Input.Town).Id;

                var createAddressServiceModel = new CreateAddressServiceModel()
                {
                    AddressText = Input.AddressText,
                    TownId      = townId
                };

                addressDataService.Create(createAddressServiceModel);

                var addressId = addressDataService.FindByName(Input.AddressText).AddressId;

                var user = new Employee
                {
                    UserName   = Input.UserName,
                    Email      = Input.Email,
                    Birthdate  = Input.BirthDate,
                    FirstName  = Input.FirstName,
                    MiddleName = Input.MiddleName,
                    LastName   = Input.LastName,
                };

                var result = await _userManager.CreateAsync(user, Input.Password);

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

                    var code = await _userManager.GenerateEmailConfirmationTokenAsync(user);

                    code = WebEncoders.Base64UrlEncode(Encoding.UTF8.GetBytes(code));
                    var callbackUrl = Url.Page(
                        "/Account/ConfirmEmail",
                        pageHandler: null,
                        values: new { area = "Identity", userId = user.Id, code = code },
                        protocol: Request.Scheme);

                    await _emailSender.SendEmailAsync(Input.Email, "Confirm your email",
                                                      $"Please confirm your account by <a href='{HtmlEncoder.Default.Encode(callbackUrl)}'>clicking here</a>.");

                    if (_userManager.Options.SignIn.RequireConfirmedAccount)
                    {
                        return(RedirectToPage("RegisterConfirmation", new { email = Input.Email }));
                    }
                    else
                    {
                        await _signInManager.SignInAsync(user, isPersistent : false);

                        //ADDING employee to an address


                        var addEmployeeToAddressServiceModel = new AddEmployeeToAddressServiceModel()
                        {
                            AddressId  = addressId,
                            EmployeeId = user.Id
                        };

                        addressDataService.AddEmployeeToAddress(addEmployeeToAddressServiceModel);

                        /////////////////////////////////////////
                        return(LocalRedirect(returnUrl));
                    }
                }
                foreach (var error in result.Errors)
                {
                    ModelState.AddModelError(string.Empty, error.Description);
                }
            }

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