public async Task <UserShortDataModel> AdminCreate(UserCreateModel model) { if (model == null) { throw new ModelDamagedException(nameof(model), "is required"); } if ((await _appUserManager.FindByEmailAsync(model.Email)) != null) { throw new EntityExistsException(nameof(model.Email), model.Email, typeof(AppUser)); } var user = new AppUser { Birthday = new DateTime(), FirstName = model.FirstName, LastName = model.LastName, Email = model.Email, Tels = model.Tels?.Select((x) => new MRUserTel { Name = x.Name, Tel = x.Number }).ToList() ?? new List <MRUserTel>(), UserName = model.Email }; var createResult = await _appUserManager.CreateAsync(user); if (!createResult.Succeeded) { throw new SystemException("Can not create user"); } await _appUserRepository.AddToRoleAsync(user, "USER", new System.Threading.CancellationToken()); UserCreateTemplateModel templateModel = new UserCreateTemplateModel { Provider = "MR Identity", CallbackUrl = "https://google.com", Email = user.Email, FirstName = user.FirstName, LastName = user.LastName }; var emailBody = await _templateParser.Render(null, EmailTemplateCollection.USER_INVITE, templateModel); await _emailSendTaskRepository.InsertEmail(user.Email, "MR identity invite", emailBody, Infrastructure.Entities.Tasks.EmailTaskBot.MadRatBot); return(_mapper.Map <UserShortDataModel>(user)); }