コード例 #1
0
 public async Task <int> SaveAddress(AddressViewModel address)
 {
     try
     {
         _dbContext.AccountAddress.Add(_map.Map <Address>(address));
         return(await _dbContext.SaveChangesAsync().ConfigureAwait(false));
     }
     catch (Exception)
     {
         throw;
     }
 }
コード例 #2
0
        public async Task <bool> Register(RegisterViewModel register)
        {
            var IsUserExist = _identityContext.Users.Any(user => user.Email.Equals(register.Email, StringComparison.OrdinalIgnoreCase));

            if (IsUserExist)
            {
                throw new VSException("Email already registered with:" + register.Email);
            }

            var User = new Account
            {
                UserName       = register.UserName,
                Email          = register.Email,
                FirstName      = register.FirstName,
                LastName       = register.LastName,
                PhoneNumber    = register.Phone,
                EmailConfirmed = true,
            };

            IdentityResult results = null;

            try
            {
                results = await _userManager.CreateAsync(User, register.Password).ConfigureAwait(false);

                if (results.Succeeded)
                {
                    await _userManager.AddToRoleAsync(User, register.Role.ToString());

                    switch (register.Role)
                    {
                    case UserRoles.Student:
                        _identityContext.Students.Add(new Student {
                            UserId = User.Id
                        });
                        break;

                    case UserRoles.Tutor:
                        _identityContext.Instructors.Add(new Instructor {
                            UserId = User.Id
                        });
                        break;

                    case UserRoles.Parent:
                    case UserRoles.Admin:
                    default:
                        return(results.Succeeded);
                    }
                    await _identityContext.SaveChangesAsync().ConfigureAwait(false);

                    // _identityContext.AccountAddress.Add(new Address {   })
                }
                return(results.Succeeded);
            }
            catch (Exception)
            {
                throw new VSException("Unable to Register With Following Errors:", results?.Errors);
            }
        }
コード例 #3
0
 public async Task <int> SaveStudent(StudentViewModel instructor)
 {
     _dbContext.Students.Add(_map.Map <Student>(instructor));
     return(await _dbContext.SaveChangesAsync().ConfigureAwait(false));
 }
コード例 #4
0
 public async Task <int> SaveInstructor(InstructorViewModel instructor)
 {
     _dbContext.Instructors.Add(_map.Map <Instructor>(instructor));
     return(await _dbContext.SaveChangesAsync().ConfigureAwait(false));
 }