public async Task <IActionResult> Create([Bind("ID,FirstName,LastName,Email,Phone")] Parent parent) { try { if (ModelState.IsValid) { _context.Add(parent); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } } catch (DbUpdateException dex) { if (dex.InnerException.Message.Contains("IX_Parents_Email")) { ModelState.AddModelError("Email", "Unable to save changes. Remember, you cannot have duplicate Email Addresses"); } else { ModelState.AddModelError("", "Unable to save changes. Try again, and if the problem persists see your system admin."); } } return(View(parent)); }
public async Task <IActionResult> Create([Bind("ID,ProgramName,ProgramDescription,ProgramJoinCode,ProgramSupervisorID")] Models.Program program) { try { if (ModelState.IsValid) { _context.Add(program); await _context.SaveChangesAsync(); return(RedirectToAction("Index", "Home")); } } catch (DbUpdateException dex) { if (dex.InnerException.Message.Contains("IX_Programs_ProgramJoinCode")) { ModelState.AddModelError("ProgramJoinCode", "Unable to save changes. Remember, you cannot have duplicate Program Join Codes."); } else { ModelState.AddModelError("", "Unable to save changes. Try again, and if the problem persists see your system admin."); } } ViewData["ProgramSupervisorID"] = new SelectList(_context.ProgramSupervisors, "ID", "Email", program.ProgramSupervisorID); return(View(program)); }
public async Task <IActionResult> CreateFromProgramDetails(int ProgramSupervisorID, int ParentID) { var conversation = new Conversation(); conversation.ParentID = ParentID; conversation.ProgramSupervisorID = ProgramSupervisorID; _context.Add(conversation); await _context.SaveChangesAsync(); conversation = _context.Conversations .Include(c => c.Messages) .Include(c => c.Parent) .Include(c => c.ProgramSupervisor) .Where(c => c.ProgramSupervisorID == ProgramSupervisorID && c.ParentID == ParentID) .FirstOrDefault(); return(View("Messages", conversation)); }
public async Task <IActionResult> Create([Bind("ID,Title,Body,ProgramID")] Announcement announcement) { if (ModelState.IsValid) { _context.Add(announcement); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["ProgramID"] = new SelectList(_context.Programs, "ID", "ProgramDescription", announcement.ProgramID); return(View(announcement)); }
public async Task <IActionResult> Create([Bind("ID,FirstName,LastName,ParentID")] Child child) { if (ModelState.IsValid) { _context.Add(child); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["ParentID"] = new SelectList(_context.Parents, "ID", "Email", child.ParentID); return(View(child)); }
public async Task <IActionResult> Create([Bind("ID,Title,Description,Date,ProgramID")] Activity activity, int programID) { string redirectAction; if (ModelState.IsValid) { _context.Add(activity); await _context.SaveChangesAsync(); redirectAction = "Details/" + activity.ProgramID; return(RedirectToAction(redirectAction, "Programs")); } ViewData["ProgramID"] = new SelectList(_context.Programs, "ID", "ProgramName", activity.ProgramID); redirectAction = "Details/" + activity.ProgramID; return(RedirectToAction(redirectAction, "Programs")); }
public async Task <IActionResult> OnPostAsync(string returnUrl = null) { returnUrl = returnUrl ?? Url.Content("~/"); if (ModelState.IsValid) { var user = new IdentityUser { UserName = Input.Email, Email = Input.Email }; var result = await _userManager.CreateAsync(user, Input.Password); var role = new IdentityRole { Name = "Parent" }; await _userManager.AddToRoleAsync(user, "Parent"); if (result.Succeeded) { _logger.LogInformation("User created a new account with password."); var parent = _context.Parents.SingleOrDefault(p => p.Email == Input.Email); if (parent == null) { parent = new Models.Parent(); parent.Email = user.Email; parent.FirstName = Input.FirstName; parent.LastName = Input.LastName; parent.Phone = Input.Phone; _context.Add(parent); await _context.SaveChangesAsync(); } else if (parent.ParentName == "Placeholder Placeholder") { parent.FirstName = Input.FirstName; parent.LastName = Input.LastName; parent.Phone = Input.Phone; await _context.SaveChangesAsync(); } var code = await _userManager.GenerateEmailConfirmationTokenAsync(user); var callbackUrl = Url.Page( "/Account/ConfirmEmail", pageHandler: null, values: new { userId = user.Id, code = code }, protocol: Request.Scheme); await _emailSender.SendEmailAsync(Input.Email, "Confirm your email", $"Please confirm your account by <a href='{HtmlEncoder.Default.Encode(callbackUrl)}'>clicking here</a>."); await _signInManager.SignInAsync(user, isPersistent : false); return(LocalRedirect(returnUrl)); } foreach (var error in result.Errors) { ModelState.AddModelError(string.Empty, error.Description); } } // If we got this far, something failed, redisplay form return(Page()); }