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 }); }
public ActionResult Index(int? groupId) { if (groupId == null) { return RedirectToAction("Index", "User"); } var service = new Service(); User user = service.GetUser(User.Identity.Name); if (service.IsMemberOfGroup(user.UserID, groupId.Value)) { GroupFeedViewModel model = service.GetGroupFeed(groupId.Value, user.UserID); if (Request.IsAjaxRequest()) { return Json(RenderPartialViewToString("GroupFeed", model), JsonRequestBehavior.AllowGet); } SetUserFeedback(); return View(model); } return RedirectToAction("Index", "User"); }
public ActionResult CreateEvent(int groupId, Event newEvent) { ViewBag.groupId = groupId; var service = new Service(); User user = service.GetUser(User.Identity.Name); if (service.IsMemberOfGroup(user.UserID, groupId) == false) { ModelState.AddModelError("Error", "Either the group doesn't exist or you do not have access to it."); return View(); } else if (newEvent.Min.HasValue && newEvent.Max.HasValue && (newEvent.Max.Value < newEvent.Min.Value)) { ModelState.AddModelError("Error", "Min can't be higher than max"); } else if (!service.ValidationOfTimeOfEvent(newEvent)) { ModelState.AddModelError("Time of event", "Date of event is not valid"); } else if (ModelState.IsValid) { newEvent.OwnerId = user.UserID; newEvent.CreationTime = DateTime.Now; newEvent.Active = true; if (service.CreateEvent(ref newEvent)) { return RedirectToAction("Index", new { groupId = groupId }); } ModelState.AddModelError("Error", "Something went wrong when trying to add your event to the group, please try again later."); return View(); } return View(); }
public ActionResult GetSideBar(int groupId) { var service = new Service(); User user = service.GetUser(User.Identity.Name); if (service.IsMemberOfGroup(user.UserID, groupId)) { if (Request.IsAjaxRequest()) { GroupFeedViewModel model = new GroupFeedViewModel(); model.SideBar = service.GetSideBar(user.UserID, groupId); model.Group = service.GetGroupById(groupId); return Json(RenderPartialViewToString("SideBar", model), JsonRequestBehavior.AllowGet); } } return Json(null, JsonRequestBehavior.AllowGet); }
public ActionResult CreateEvent(int groupId) { var service = new Service(); User user = service.GetUser(User.Identity.Name); if (service.IsMemberOfGroup(user.UserID, groupId) == false) { return RedirectToAction("Index", "User"); } ViewBag.groupId = groupId; return View(); }