public async Task <ActionResult> Create([Bind(Include = "Id,Name,MobileNumber,Email,DepartmentId,ApplicationUserId")] Teacher teacher) { if (ModelState.IsValid) { ApplicationUser applicationUser = new ApplicationUser { Email = teacher.Email, UserName = teacher.Email, UserType = 2 }; var userManager = new UserManager <ApplicationUser>(new UserStore <ApplicationUser>(StudentMsDbSingleton.SingletonStudentDb())); var studentResult = await userManager.CreateAsync (applicationUser, teacher.Email); if (studentResult.Succeeded) { teacher.ApplicationUserId = applicationUser.Id; db.Teachers.Add(teacher); await db.SaveChangesAsync(); return(RedirectToAction("Index")); } } ViewBag.ApplicationUserId = new SelectList(db.Users, "Id", "Email", teacher.ApplicationUserId); ViewBag.DepartmentId = new SelectList(db.Departments, "Id", "Name", teacher.DepartmentId); return(View(teacher)); }
public async Task <ActionResult> Create([Bind(Include = "Id,StudentId,DepartmentId,AboutYou")] ApplicationForm applicationForm) { applicationForm.StudentId = 0; if (ModelState.IsValid) { var userId = User.Identity.GetUserId(); applicationForm.StudentId = db.Students.FirstOrDefault(f => f.ApplicationUserId == userId).Id; var app = db.ApplicationForms.Add(applicationForm); var value = await db.SaveChangesAsync(); if (value > 0) { ApplicationStatus applicationStatus = new ApplicationStatus { ApplicationFormId = app.Id, IsAccepted = null, TeacherId = null }; db.ApplicationStatuses.Add(applicationStatus); await db.SaveChangesAsync(); } return(RedirectToAction("Profile", "Students")); } ViewBag.DepartmentId = new SelectList(db.Departments, "Id", "Name", applicationForm.DepartmentId); ViewBag.StudentId = new SelectList(db.Students, "Id", "Name", applicationForm.StudentId); return(View(applicationForm)); }
public async Task <ActionResult> Create([Bind(Include = "Id,Name,DepartmentId,TeacherId, Description")] Course course) { if (ModelState.IsValid) { db.Courses.Add(course); await db.SaveChangesAsync(); return(RedirectToAction("Index")); } ViewBag.DepartmentId = new SelectList(db.Departments, "Id", "Name", course.DepartmentId); return(View(course)); }
public async Task <ActionResult> Edit([Bind(Include = "Id,Name,Address,Sex,ApplicationUserId")] Student student) { if (ModelState.IsValid) { db.Entry(student).State = EntityState.Modified; await db.SaveChangesAsync(); return(RedirectToAction("Profile")); } ViewBag.ApplicationUserId = new SelectList(db.Users, "Id", "Email", student.ApplicationUserId); return(View(student)); }
public Task <int> Insert(Student entity) { _studentMsDb.Students.Add(entity); return(_studentMsDb.SaveChangesAsync()); }