public HttpResponseMessage PostGroupCollection(APISignedRequest request)
        {
            CompetitionModel comp;
            var groupCollection = GetRequestParameter <API_AgeGroupCollection>(request, out comp);

            List <Comp_AgeGroupModel> addedGroups = new List <Comp_AgeGroupModel>();

            foreach (var agApi in groupCollection.Data)
            {
                addedGroups.Add(SaveOneAgeGroup(comp, agApi));
            }
            db.SaveChanges();
            HashSet <int> savedGroups = new HashSet <int>(addedGroups.Select(g => g.AgeGroupId));
            //comp = db.Competitions.Find(id);
            var toRemove = comp.AgeGroups.ToList().Where(g => !savedGroups.Contains(g.AgeGroupId)).ToArray();

            for (int i = 0; i < toRemove.Length; i++)
            {
                db.CompetitionAgeGroups.Remove(toRemove[i]);
            }
            db.SaveChanges();
            var res = new API_AgeGroupCollection {
                Data = addedGroups.Select(gr => gr.ToApi()).ToArray()
            };

            return(Request.CreateResponse <API_AgeGroupCollection>(HttpStatusCode.Created, res));
        }
 public AsyncRequestResult BeginPostGroupCollection(API_AgeGroupCollection ageGroups, RequestCompleted <API_AgeGroupCollection> callback, Object asyncState)
 {
     return(BeginPostSerializableT("Calendar", "PostGroupCollection", String.Empty, ageGroups, callback, asyncState, true));
 }
 public API_AgeGroupCollection PostGroupCollection(API_AgeGroupCollection ageGroups)
 {
     return(PostSerializableT("Calendar", "PostGroupCollection", String.Empty, ageGroups));
 }