public async Task <Result <bool> > ContactUs(int userId, ContactUsViewModel contactUs) { try { var body = File.ReadAllText("wwwroot/html/contactus.html"); body = body.Replace("{user-email}", contactUs.Email); body = body.Replace("{user-id}", userId.ToString()); body = body.Replace("{user-message}", contactUs.Message); await _mailProvider.SendAsync(new MailMessageViewModel { From = contactUs.Email, To = MailProvider.SMTP_USER, Subject = contactUs.Subject, Body = body, IsBodyHtml = true }); return(ResultHelper.Succeeded(true)); } catch (Exception e) { return(ResultHelper.Failed <bool>(message: e.Message)); } }
public async Task SendAsync([FromBody] RegistrationEmailViewModel message) { var messageBody = await _mailProvider.RenderMailViewAsync(ControllerContext, MailTemplate.RegistrationComplete, message); await _mailProvider.SendAsync(message.To, message.Subject, messageBody); }
public async Task <Result <bool> > AddUser(RegisterationViewModel userViewModel) { try { var user = new UserEntity { Name = userViewModel.Name, Email = userViewModel.Email, PhoneNumber = userViewModel.PhoneNumber, Address = userViewModel.Address, Type = userViewModel.Type, Picture = userViewModel.Picture, Gender = userViewModel.Gender, }; // Check for Type if (!Enum.IsDefined(typeof(EUserType), userViewModel.Type)) { throw new Exception(EResultMessage.NotUserType.ToString()); } // Add user Typr user.Type = userViewModel.Type; if (userViewModel.Password != userViewModel.RepeatPassword) { throw new Exception(EResultMessage.PasswordNotMatched.ToString()); } // Hash user password user.HashPassword = Protected.CreatePasswordHash(userViewModel.Password); // Add user var result = Add(user); if (result == null) { throw new Exception(EResultMessage.DatabaseError.ToString()); } SaveChanges(); var token = _tokenManager.GenerateUserToken(result).Token; var confirmLink = string.Format("{0}/api/user/confirm-account", _requestAttributes.AppBaseUrl); string body = File.ReadAllText("wwwroot/html/registartion.html"); body = body.Replace("{link-path}", confirmLink); body = body.Replace("{user-name}", user.Name); body = body.Replace("{user-id}", user.Id.ToString()); body = body.Replace("{user-token}", token); await _mailProvider.SendAsync(new MailMessageViewModel { From = MailProvider.SMTP_USER, To = user.Email, IsBodyHtml = true, Body = body, Subject = "Confirm your account on Got It" }); return(ResultHelper.Succeeded(true, message: EResultMessage.RegistrationDone.ToString())); } catch (DuplicateDataException) { return(ResultHelper.Failed(data: false, message: EResultMessage.EmailExists.ToString())); } catch (Exception e) { return(ResultHelper.Failed <bool>(message: e.Message)); } }