public async Task <IActionResult> Post(string email, int roleType) { bool emailExist = await userRepository.DoesEmailExist(email); if (!emailExist) { Mdls.Invite invite = new Mdls.Invite { Email = email, ParticipationRoleType = (Mdls.RoleType)roleType }; string inviteId = await inviteRepository.Add(invite); await emailProvider.SendEmailAsHtml(email, EmailTemplate.getInviteTemplate(inviteId)); } else { return(BadRequest(new DTOs.Error(ErrorResponses.NVITE_USER_EXIST))); } return(Ok(new ActionResponse { State = true })); }
public IActionResult InviteStudents(string ClassId, string emails) { int id = Convert.ToInt32(ClassId); Classroom classroom = _classRepo.GetClassroom(id); AppUser user = _userManager.FindByIdAsync(_userManager.GetUserId(HttpContext.User)).Result; string[] Emails = emails.Split(" "); foreach (string email in Emails) { //Send Mail string DigiClassEmailId = "emailid"; string DigiClassPassword = "******"; MimeMessage message = new MimeMessage(); MailboxAddress from = new MailboxAddress(user.UserName, DigiClassEmailId); message.From.Add(from); MailboxAddress to = new MailboxAddress("Student", email); message.To.Add(to); message.Subject = "Invite to " + classroom.title + " DigiClassroom"; BodyBuilder bodyBuilder = new BodyBuilder(); bodyBuilder.HtmlBody = "<div>" + "Hello Student," + "<br/><br/>" + "You've been invited to <b>" + classroom.title + "<b/>" + " DigiClassroom!" + "<br/><br/>" + "<a target=\"_blank\" style=\"color:#1b6ec2\" href=\"https://localhost:44300/Classroom/AcceptStudentInvite/" + classroom.ID + "\">Accept Invitation</a> " + "<a target=\"_blank\" style=\"color:#dc3545\" href=\"https://localhost:44300/Classroom/DeclineStudentInvite/" + classroom.ID + "\">Decline Invitation</a>" + "</div>"; message.Body = bodyBuilder.ToMessageBody(); SmtpClient client = new SmtpClient(); client.CheckCertificateRevocation = false; client.Connect("smtp.gmail.com", 465, true); client.Authenticate(DigiClassEmailId, DigiClassPassword); client.Send(message); client.Disconnect(true); client.Dispose(); //Mail sent Invite invite = new Invite { ClassroomId = id, Email = email }; _inviteRepo.Add(invite); } return(RedirectToAction("Home", new { id = id, loadPartial = "People" })); }
public async Task <int> Add(string url, string inviter, string emails) { string[] emailArray = emails.Split(new string[] { "\n", "\r\n", ",", ";", " " }, StringSplitOptions.RemoveEmptyEntries); int result = 0; foreach (string email in emailArray) { string code = CreateRandomCode(6); Invite invite = new Invite(); invite.Inviter = inviter; invite.Email = email; invite.Code = code; result += await _inviteRepository.Add(invite); await SendEmail(email, url, code); } return(result); }
public Invite InviteUser(User user) { var invite = new Invite { IdUser = user.Id, LinkKey = Guid.NewGuid().ToString().Replace("-", ""), IsUsed = false, ExpiryDate = DateTime.UtcNow.AddHours(1) }; _inviteRepository.Add(invite); var baseUrl = BaseUrl; var message = $"You are invited to Mexem reporting system. Please follow a link to get registered: <a href=\"{baseUrl}/registration/confirm/{invite.LinkKey}\">link</a>"; var title = "IBAR App Confirm registration"; _messengerService.SendEmail(user.Email, message, title, true); return(invite); }
public async Task <Guid> CreateInvite(Guid id, EmailRequestModel model) { try { var employee = await _employeeRepository.GetById(id); if (employee == null) { throw new Exception("Employee is null"); } var invite = new Invite(model.email, id); _inviteRepository.Add(invite); await _inviteRepository.SaveChanges(); return(invite.Id); } catch (Exception e) { throw e; } }