public ActionResult Invite(int userID) { EmailaddressesViewModel invitedemails = new EmailaddressesViewModel(); invitedemails.UserID = userID; return View(invitedemails); }
public ActionResult Invite(EmailaddressesViewModel invitedemails) { if (ModelState.IsValid) { int userid = invitedemails.UserID; string invalidemails = ""; char[] delimiters = (",: ").ToCharArray(); List<string> emails = invitedemails.Emailaddresses.Split(delimiters).ToList(); IUserMailer mailer = new UserMailer(); EmailModel emailmodel = new EmailModel(); emailmodel.From = db.UserProfiles.Where(x => x.UserId == userid).First().UserName; foreach (var emailaddress in emails) { if (IsValidEmail(emailaddress)) { emailmodel.To = emailaddress; Common.sendMail(emailmodel, EmailExist(emailaddress)); InsertRequestInfo(userid, emailmodel.From, emailmodel.To); } else { invalidemails = invalidemails + "," + emailaddress; } } if (invalidemails == "") { //AccountController acc = new AccountController(); return RedirectPage(userid); } else invitedemails.Emailaddresses = invalidemails; invitedemails.ErrorMessage = "Please correct these emailaddresses"; return View(invitedemails); } else { return View(); } }