// Going through a 'normal' MVC controller because the 'Group' demos require SessionState // which is not aviable in the WebAPI/REST services. public ActionResult AddGroup(Group group) { Guard.ArgumentNotNull(group, "Group"); var groups = this.groupService.Add(group); // will return a refreshed list of groups. return this.Json(groups, JsonRequestBehavior.AllowGet).AsCamelCaseResolverResult(); }
public IEnumerable<Group> Add(Group group) { Guard.ArgumentNotNull(group, "group"); List<Group> groups = this.sessionService.Get<List<Group>>("Groups") ?? new List<Group>(); groups.Add(group); this.sessionService.Add("Groups", groups); return groups; }
public Group ToggleGroupMember(Group group, Member person) { Guard.ArgumentNotNull(group, "group"); Guard.ArgumentNotNull(person, "person"); var groups = this.sessionService.TryGet<Group, IEnumerable<Group>>("Groups", group, Add); var targetGroup = groups.Where(g => g.GroupId.Equals(group.GroupId)).FirstOrDefault(); var isInGroup = (targetGroup.Members.Count(m => m.PersonId.Equals(person.PersonId)) == 0) ? false : true ; if (!isInGroup) { targetGroup.Members.Add(person); } else { var removePerson = targetGroup.Members.FirstOrDefault(m => m.PersonId == person.PersonId); targetGroup.Members.Remove(removePerson); } this.sessionService.Add("Groups", groups); // or (using HttpContext) Session["Groups"] = groups; return targetGroup; }