Exemple #1
0
 public ActionResult AddMember(int groupId, string username)
 {
     var service = new Service();
     User user = service.GetUser(User.Identity.Name);
     User member = service.GetUser(username);
     if (service.IsOwnerOfGroup(user.UserID, groupId) == false)
     {
         TempData["message"] = new Message("Only the owner of a group can add a member to it", MessageType.INFORMATION);
     }
     else if (member == null)
     {
         TempData["message"] = new Message("The username " + username + " could not be found.", MessageType.INFORMATION);
     }
     else if (User.Identity.Name == member.UserName)
     {
         TempData["message"] = new Message("You are already in the group.", MessageType.INFORMATION);
     }
     else if (service.IsMemberOfGroup(member.UserID, groupId))
     {
         TempData["message"] = new Message(username + " is already in the group.", MessageType.INFORMATION);
     }
     else if (service.AddMember(member.UserID, groupId))
     {
         TempData["message"] = new Message(member.UserName + " was added to the group.", MessageType.SUCCESS);
     }
     else
     {
         TempData["message"] = new Message("An error occured when trying to add " + username + "to the group, please try again later.", MessageType.ERROR);
     }
     if (Request.IsAjaxRequest())
     {
         return Json(new { member = member, message = TempData["message"] as Message }, JsonRequestBehavior.AllowGet);
     }
     return RedirectToAction("Index", new { groupId = groupId });
 }