public ActionResult Create([Bind(Include = "StudentID,FirstName,LastName,Gender,Birthday,Email,PhoneNumber")] Student student) { if (ModelState.IsValid) { db.Students.Add(student); db.SaveChanges(); return(RedirectToAction("StudentList")); } return(View(student)); }
public ActionResult Create([Bind(Include = "Id,Name")] Administrator administrator) { if (ModelState.IsValid) { db.Administrators.Add(administrator); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(administrator)); }
public ActionResult Create([Bind(Include = "TeacherID,FirstName,LastName,Qualification,Email,PhoneNumber,Gender")] Teacher teacher) { if (ModelState.IsValid) { db.Teachers.Add(teacher); db.SaveChanges(); return(RedirectToAction("TeacherList")); } return(View(teacher)); }
public ActionResult Add(UserRole userRole) { StudentManagementDbContext context = new StudentManagementDbContext(); var roleManager = new RoleManager <IdentityRole>(new RoleStore <IdentityRole>(context)); var UserManager = new UserManager <ApplicationUser>(new UserStore <ApplicationUser>(context)); try { var allRoles = context.Roles.ToList(); string rolesName = null; if (allRoles != null && allRoles.Count > 0) { var item = allRoles.Where(s => s.Id == userRole.RoleId).FirstOrDefault(); rolesName = item.Name; } var result = UserManager.AddToRole(userRole.UserId, rolesName); context.SaveChanges(); } catch (Exception ex) { throw ex; } // Lam sao lu DB return(RedirectToAction("Index")); }
public ActionResult Create(Department department) { db.Departments.Add(department); bool isSaved = db.SaveChanges() > 0; if (isSaved) { ViewBag.message = "successfully department added "; } return(View()); }
public ActionResult Create(Student student) { if (ModelState.IsValid) { db.Students.Add(student); bool isSaved = db.SaveChanges() > 0; if (isSaved) { ViewBag.message = "Student Create Successfully"; } ViewBag.DepartmentId = new SelectList(db.Departments, "Id", "Name", student.DepartmentId); } return(View()); }
public ActionResult Create(IdentityRole Role) { if (User.Identity.IsAuthenticated) { if (!isAdminUser()) { return(RedirectToAction("Index", "Home")); } } else { return(RedirectToAction("Index", "Home")); } context.Roles.Add(Role); context.SaveChanges(); return(RedirectToAction("Index")); }