Beispiel #1
0
        public ActionResult Create(Link link)
        {
            if (ModelState.IsValid)
            {
                db.Links.Add(link);
                db.SaveChanges();
                return RedirectToAction("Index");
            }

            ViewBag.ProfessorID = new SelectList(db.Professors, "ProfessorID", "FirstName", link.ProfessorID);
            ViewBag.UserID = new SelectList(db.Users, "UserID", "Username", link.UserID);
            ViewBag.RoleID = new SelectList(db.Roles, "RoleID", "Name", link.RoleID);
            return View(link);
        }
Beispiel #2
0
        public ActionResult Create(Link link)
        {
            if (ModelState.IsValid)
            {

                //Do not allow user to be assigned to a role he is already in
                if (!Roles.IsUserInRole(link.UserName, link.Role))
                {
                    db.Links.Add(link);
                    db.SaveChanges();

                    //Adds role to a user (Membership)
                    Roles.AddUserToRole(link.UserName, link.Role);
                }

                return RedirectToAction("Index");
            }

            ViewBag.ProfessorID = new SelectList(db.Professors, "ProfessorID", "FirstName", link.ProfessorID);
            return View(link);
        }
Beispiel #3
0
 public ActionResult Edit(Link link)
 {
     if (ModelState.IsValid)
     {
         db.Entry(link).State = EntityState.Modified;
         db.SaveChanges();
         return RedirectToAction("Index");
     }
     ViewBag.ProfessorID = new SelectList(db.Professors, "ProfessorID", "FirstName", link.ProfessorID);
     ViewBag.UserID = new SelectList(db.Users, "UserID", "Username", link.UserID);
     ViewBag.RoleID = new SelectList(db.Roles, "RoleID", "Name", link.RoleID);
     return View(link);
 }