Пример #1
0
        /// <summary>
        /// Gets the org identifier from CRM identifier.
        /// </summary>
        /// <param name="orgCRMId">The org CRM identifier.</param>
        /// <returns>ApplicationUserDto object.</returns>
        public ApplicationUserDto GetOrgIdFromCRMId(string orgCRMId)
        {
            ApplicationUser appUser = new ApplicationUser();
            try
            {
                appUser = this.appUser.Find(x => x.CRMId == orgCRMId).FirstOrDefault() ?? new ApplicationUser();
            }
            catch (Exception ex)
            {
                this.LoggerService.LogException("GetOrgIdFromCRMId :- " + ex.Message);
            }

            return this.mapperFactory.GetMapper<ApplicationUser, ApplicationUserDto>().Map(appUser);
        }
Пример #2
0
        /// <summary>
        /// Registers the user.
        /// </summary>
        /// <param name="userModel">The user model.</param>
        /// <returns>Identity object</returns>
        public async Task<IdentityResult> RegisterUser(UserModel userModel)
        {
            ApplicationUser user = new ApplicationUser { Email = userModel.EmailId, UserName = userModel.EmailId, Name = userModel.Name };
            var existingUser = this.userManager.FindByName(userModel.EmailId);

            if (existingUser != null)
            {
                var errorResult = new IdentityResult(new[] { string.Format("Email {0} already exists!", userModel.EmailId) });
                return errorResult;
            }

            user.IsActive = true;
            if (userModel.UserRole == Roles.Company.ToString())
            {
                user.AccountType = 3;
            }
            else if (userModel.UserRole == Roles.Customer.ToString())
            {
                user.AccountType = 2;
            }

            var result = await this.userManager.CreateAsync(user, userModel.Password);

            if (result != null && result.Succeeded)
            {
                this.userManager.AddToRole(user.Id, userModel.UserRole);
                var newUser = this.mapperFactory.GetMapper<ApplicationUser, ApplicationUserDto>().Map(user);
                newUser.RoleName = userModel.UserRole;

                this.emailQueueService.SendActivationEmail(newUser);
            }

            return result;
        }