//
 // GET: /Membership/
 public ActionResult Index()
 {
     List<UserMembership> members = new List<UserMembership>();
     foreach (UserProfile user in db.UserProfiles.ToList())
     {
         UserMembership mem = new UserMembership();
         mem.User = user;
         String[] roles =Roles.GetRolesForUser(user.UserName);
         if(roles.Length > 0)
         mem.Role = roles[0];
         members.Add(mem);
     }
     return View(members);
 }
 //
 // GET: /Membership/Edit/5
 public ActionResult Edit(int id = 0)
 {
     UserProfile userprofile = db.UserProfiles.Find(id);
     UserMembership member = new UserMembership();
     member.User = userprofile;
     String[] roles = Roles.GetRolesForUser(userprofile.UserName);
     if (roles.Length > 0)
         member.Role = roles[0];
     List<SelectListItem> RoleItem = new List<SelectListItem>();
     RoleItem.Add(new SelectListItem
     {
         Text = "Administrator",
         Value = "Administrator"
     });
     RoleItem.Add(new SelectListItem
     {
         Text = "Manager",
         Value = "Manager",
     });
     RoleItem.Add(new SelectListItem
     {
         Text = "Graphic Creater",
         Value = "GraphicCreater"
     });
     RoleItem.Add(new SelectListItem
     {
         Text = "Banned",
         Value = "Banned"
     });
     ViewBag.RoleTypes = RoleItem;
     if (userprofile == null)
     {
         return HttpNotFound();
     }
     return View(member);
 }
 public ActionResult Edit(UserMembership member, string RoleTypes)
 {
     if (ModelState.IsValid)
     {
         //db.Entry(userprofile).State = EntityState.Modified;
         //db.SaveChanges();
         String[] oldroles = Roles.GetRolesForUser(member.User.UserName);
         if(oldroles.Length > 0)
             Roles.RemoveUserFromRoles(member.User.UserName, oldroles);
         Roles.AddUserToRole(member.User.UserName, RoleTypes);
         return RedirectToAction("Index");
     }
     return View(member.User);
 }