public virtual ActionResult SendPilotLicense(string name, string email) { var org = _context.Users .Where(x => x.Id == CurrentUserId) .Select(x => x.Organization) .Include(x => x.FpUsedPilotLicenses) .SingleOrDefault(); if (string.IsNullOrWhiteSpace(org.FillPerfectPilotKey)) { return(RedirectToAction(MVC.Organization.Dashboard.Index())); } // Make sure they have a free license if (org.FpUsedPilotLicenses.Count >= org.FpPilotLicenseCount) { ModelState.AddModelError("", "You do not have any free licenses available"); } // Do some simple validation if (string.IsNullOrWhiteSpace(name) || string.IsNullOrWhiteSpace(email)) { ModelState.AddModelError("", "The student name or email fields are required"); } if (ModelState.IsValid) { // Set them up in the database var license = new DomainModel.Entities.FillPerfect.FpOrgPilotUsedLicense { FullName = name.Trim(), Email = email.Trim(), LicenseGrantDate = DateTime.Now }; license.Organization = org; _context.FpOrgPilotUsedLicenses.Add(license); _context.SaveChanges(); // Email the user SendLicenseToUser(license); } if (!ModelState.IsValid) { return(View(MVC.FillPerfect.OrgPilotDashboard.Views.Index, CreateDashboardViewModel(org))); } else { return(RedirectToAction(MVC.FillPerfect.OrgPilotDashboard.Index(true))); } }
public virtual ActionResult SendPilotLicense(string name, string email) { var org = _context.Users .Where(x => x.Id == CurrentUserId) .Select(x => x.Organization) .Include(x => x.FpUsedPilotLicenses) .SingleOrDefault(); if (string.IsNullOrWhiteSpace(org.FillPerfectPilotKey)) return RedirectToAction(MVC.Organization.Dashboard.Index()); // Make sure they have a free license if (org.FpUsedPilotLicenses.Count >= org.FpPilotLicenseCount) ModelState.AddModelError("", "You do not have any free licenses available"); // Do some simple validation if (string.IsNullOrWhiteSpace(name) || string.IsNullOrWhiteSpace(email)) ModelState.AddModelError("", "The student name or email fields are required"); if (ModelState.IsValid) { // Set them up in the database var license = new DomainModel.Entities.FillPerfect.FpOrgPilotUsedLicense { FullName = name.Trim(), Email = email.Trim(), LicenseGrantDate = DateTime.Now }; license.Organization = org; _context.FpOrgPilotUsedLicenses.Add(license); _context.SaveChanges(); // Email the user SendLicenseToUser(license); } if (!ModelState.IsValid) return View(MVC.FillPerfect.OrgPilotDashboard.Views.Index, CreateDashboardViewModel(org)); else return RedirectToAction(MVC.FillPerfect.OrgPilotDashboard.Index(true)); }