示例#1
0
        public async Task <IActionResult> Create(Models.Users.CreateUserViewModel createUserViewModel)
        {
            if (ModelState.IsValid)
            {
                var userService = HttpContext.RequestServices.GetService <IUserService>();
                var mapper      = HttpContext.RequestServices.GetService <IMapper>();
                await userService.CreateUser(TenantID, mapper.Map <Models.Users.CreateUserViewModel, ViewModels.Users.CreateUserViewModel>(createUserViewModel));

                var emailModel = new AddUserEmailNotificationModel
                {
                    FirstName   = createUserViewModel.FirstName,
                    LastName    = createUserViewModel.LastName,
                    JournalName = GetService <ITenantService>().GetTenant(JMSUser.TenantId.Value).JournalName,
                    JournalPath = TenantID,
                    RoleNames   = createUserViewModel.Roles.Select(x => ((Role)x).ToString()).ToList()
                };
                try
                {
                    await SendAddUserEmail(emailModel, createUserViewModel.Email);
                }
                catch (System.Exception ex)
                {
                    HttpContext.RiseError(ex);
                    AddFailMessage("User has been Added  but failed to send confirmation email to user.");
                }
                return(RedirectToAction("Index"));
            }
            return(View());
        }
示例#2
0
        private async Task SendAdminEmail(AddUserEmailNotificationModel emailModel, string email)
        {
            var emailBody = await GetService <IRazorViewToStringRenderer>().RenderViewToStringAsync(@"/Views/EmailTemplates/AddUserNotification.cshtml", emailModel);

            var mailMessage = new MailMessage(_configuration[JMSSetting.SenderEmail], email, _configuration[JMSSetting.AccountConfirmationEmailSubject], emailBody)
            {
                IsBodyHtml = true
            };

            GetService <IEmailSender>().SendEmail(mailMessage);
        }
示例#3
0
        public async Task <IActionResult> Create(Models.Journals.CreateJournalModel model)
        {
            if (ModelState.IsValid)
            {
                await _tenantService.CreateTenant(new ViewModels.Journals.CreateJournalModel
                {
                    IsActive     = model.IsActive,
                    JournalName  = model.JournalName,
                    JournalPath  = model.JournalPath,
                    PhoneNumber  = model.PhoneNumber,
                    FirstName    = model.FirstName,
                    LastName     = model.LastName,
                    Email        = model.Email,
                    JournalTitle = model.JournalTitle
                }, model.Logo.OpenReadStream(), model.Logo.FileName);

                var emailModel = new AddUserEmailNotificationModel
                {
                    FirstName   = model.FirstName,
                    LastName    = model.LastName,
                    JournalName = model.JournalName,
                    JournalPath = model.JournalPath,
                    RoleNames   = new List <string> {
                        RoleName.Admin
                    }
                };
                try
                {
                    await SendAdminEmail(emailModel, model.Email);
                }
                catch (System.Exception ex)
                {
                    HttpContext.RiseError(ex);
                    AddFailMessage("Journal has been Created  but failed to send confirmation email to Admin.");
                }
                return(RedirectToAction("Index"));
            }
            return(View());
        }
示例#4
0
        public async Task <IActionResult> CreateAdmin(Models.Journals.CreateJournalAdminModel model)
        {
            if (ModelState.IsValid)
            {
                await _tenantService.CreateTenantAdmin(new ViewModels.Journals.CreateJournalAdminModel
                {
                    Active      = model.Active,
                    FirstName   = model.FirstName,
                    LastName    = model.LastName,
                    PhoneNumber = model.PhoneNumber,
                    Email       = model.Email,
                    TenantId    = model.TenantId
                });

                var journal    = _tenantService.GetTenant(model.TenantId);
                var emailModel = new AddUserEmailNotificationModel
                {
                    FirstName   = model.FirstName,
                    LastName    = model.LastName,
                    JournalName = journal.JournalName,
                    JournalPath = journal.JournalPath,
                    RoleNames   = new List <string> {
                        RoleName.Admin
                    }
                };
                try
                {
                    await SendAdminEmail(emailModel, model.Email);
                }
                catch (System.Exception ex)
                {
                    HttpContext.RiseError(ex);
                    AddFailMessage("Journal has been Created  but failed to send confirmation email to Admin.");
                }
                return(Json(new { Success = true }));
            }
            return(Json(new { Success = false }));
        }