public ActionResult SendToEmail(string kindergartenId, int id, string email) { Statement statement = StatementManager.GetStatementById(id); if (User.Identity.IsAuthenticated && ((User.IsInRole("Administrator") && statement.KindergartenId == User.Identity.GetUserId()) || (User.IsInRole("Admin")))) { try { Kindergarten Kindergarten = KindergartenManager.GetKindergartenById(statement.KindergartenId); SiteUser siteUser = SiteUserManager.GetSiteUserById(statement.SiteUserId); StatementListItemViewModel model = new StatementListItemViewModel { Statement = statement, UserPrivileges = StatementManager.GetUserPrivilegesByStatementId(id), KindergartenName = Kindergarten.Name, UserName = siteUser.FullName }; MailCustom.Mail(email, "Заява в електронну чергу #" + model.Statement.Id, GetAnswer(model)); return(RedirectToAction("Statements", "Kindergarten", new { kindergartenId })); } catch { return(RedirectToAction("Statements", "Kindergarten", new { kindergartenId })); } } ; return(RedirectToAction("Index", "Home")); }
public ActionResult AddKindergarten(AddKindergartenViewModel model) { if (User.Identity.IsAuthenticated && User.IsInRole("Admin")) { if (ModelState.IsValid) { var user = new ApplicationUser { UserName = model.Email, Email = model.Email }; string password = Guid.NewGuid().ToString("N"); if (ApplicationManager.IsEmailExist(model.Email)) { ModelState.AddModelError("Email", "Такий емейл вже використовується"); return(View(model)); } else { var result = UserManager.Create(user, password); if (result.Succeeded) { KindergartenManager.AddKindergarten(model, user.Id, Server); UserManager.AddToRole(user.Id, "Administrator"); MailCustom.Mail(model.Email, "IStudy password", GetAnswer(model.Email, password)); return(RedirectToAction("Kindergartens", "Admin")); } AddErrors(result); } } return(View(model)); } return(RedirectToAction("Index", "Home")); }