Exemple #1
0
 public ActionResult RemoveMember(int groupId, int memberId)
 {
     var service = new Service();
     User user = service.GetUser(User.Identity.Name);
     User member = null;
     if (memberId == user.UserID)
     {
         TempData["message"] = new Message("You left the group.", MessageType.SUCCESS);
         service.RemoveMember(memberId, groupId);
         return RedirectToAction("Index", "User");
     }
     else if (service.IsOwnerOfGroup(user.UserID, groupId) == false)
     {
         TempData["message"] = new Message("You are not the owner of this group.", MessageType.WARNING);
     }
     else if (service.RemoveMember(memberId, groupId))
     {
         member = service.GetUser(memberId);
         TempData["message"] = new Message(member.DisplayName + " has been removed from the group", MessageType.SUCCESS);
     }
     if (Request.IsAjaxRequest())
     {
         return Json(new { member = member, message = TempData["message"] as Message }, JsonRequestBehavior.AllowGet);
     }
     return RedirectToAction("Index", "Group", new { groupId = groupId });
 }