Пример #1
0
 public List<Data.Models.Client> ReadClients(string path)
 {
     var list = new List<Data.Models.Client>();
     var sr = new StreamReader(path);
     try
     {
         string line;
         while ((line = sr.ReadLine()) != null)
         {
             var array = line.Split(',', '\t');
             var services = new Data.Models.Client
             {
                 Lastname = array[0],
                 Name = array[1],
                 MiddleName = array[2],
                 Date = array[3],
                 AgeCategory = array[4],
                 Decor = array[5],
                 Payment = array[6],
                 Visit = array[7],
                 Directions = new List<Data.Models.Direction>()
                 {
                  new Data.Models.Direction()
                 {
                 NameOfDirection = array[8]
                 }
                 },
                 Services = new List<Data.Models.Service>()
                 {
                     new Data.Models.Service()
                     {
                         NameService = array[9],
                         Duration = int.Parse(array[10]),
                         Cost = int.Parse(array[11])
                     }
                 },
                 Discounts = new List<Discount>()
                 {
                     new Discount()
                     {
                         Code = Convert.ToInt32(array[12]),
                         Size = Convert.ToInt32(array[13])
                     }
                 }
             };
             list.Add(services);
         }
     }
     catch (Exception ex)
     {
         Console.WriteLine(ex.Message);
     }
     finally
     {
         sr.Close();
     }
     return list;
 }
Пример #2
0
        public async Task <IActionResult> OnPostAsync(string returnUrl = null)
        {
            returnUrl ??= Url.Content("~/");
            ExternalLogins = (await _signInManager.GetExternalAuthenticationSchemesAsync()).ToList();
            if (ModelState.IsValid)
            {
                ApplicationUser user;
                IdentityResult  createUser;
                IdentityResult  addRole;

                if (Input.AccountType == AccountType.Host)
                {
                    user = new Host {
                        UserName = Input.Email, Email = Input.Email, CreatedOn = DateTime.UtcNow
                    };
                    createUser = await _userManager.CreateAsync(user, Input.Password);

                    addRole = await _userManager.AddToRoleAsync(user, AccountType.Host);
                }
                else
                {
                    user = new Data.Models.Client {
                        UserName = Input.Email, Email = Input.Email, CreatedOn = DateTime.UtcNow
                    };
                    createUser = await _userManager.CreateAsync(user, Input.Password);

                    addRole = await _userManager.AddToRoleAsync(user, AccountType.Client);
                }

                if (createUser.Succeeded && addRole.Succeeded)
                {
                    _logger.LogInformation("User created a new account with password, account type, and role.");

                    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, returnUrl = returnUrl },
                        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, returnUrl = returnUrl }));
                    }
                    else
                    {
                        await _signInManager.SignInAsync(user, isPersistent : false);

                        return(LocalRedirect(returnUrl));
                    }
                }

                foreach (var error in createUser.Errors)
                {
                    ModelState.AddModelError(string.Empty, error.Description);
                }

                foreach (var error in addRole.Errors)
                {
                    ModelState.AddModelError(string.Empty, error.Description);
                }
            }

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