public async Task <int?> NewGameHost(int venueID, DateTime when, EventTypeEnum eventType, int limitOnNumberOfPlayers, List <int> invitees, string comments) { string url = WebApiUrl + "GameHosts/NewGameHost2"; try { NewGameHostWebModel2 model = new NewGameHostWebModel2() { VenueID = venueID, When = when.ToUniversalTime(), When_InLocalTimeZone = when, EventType = eventType, LimitOnNumberOfPlayers = limitOnNumberOfPlayers, Invitees = invitees, Comments = comments, }; string json = await this.sendPostRequestAndReceiveResponse(url, model, true); int modelResponse = JsonConvert.DeserializeObject <int>(json); return(modelResponse); } catch (Exception exc) { LastExceptionUrl = url; LastException = exc; return(null); } }
public async Task<int> NewGameHost2(NewGameHostWebModel2 model) { var me = new UserProfileLogic(db).GetAthleteForUserName(this.User.Identity.Name); var venue = db.Venues.SingleOrDefault(i => i.VenueID == model.VenueID); List<Athlete> playersToInvite = new List<Athlete>(); if (model.Invitees != null) { var ids = model.Invitees.Distinct().ToList(); if (ids.Count > 100) throw new ApplicationException("Too many athletes are being invited."); foreach (var id in ids) playersToInvite.Add(db.Athletes.Single(i => i.AthleteID == id)); } if ((model.When - DateTime.UtcNow).TotalHours < -1) throw new Exception("when is in the past"); // create the gamehost GameHost gameHost = new GameHost() { AthleteID = me.AthleteID, TimeCreated = DateTime.UtcNow, VenueID = model.VenueID, Visibility = 0,//model.Visibility, When = model.When, When_InLocalTimeZone = model.When_InLocalTimeZone, LimitOnNumberOfPlayers = model.LimitOnNumberOfPlayers, EventType = (int)model.EventType, }; db.GameHosts.Add(gameHost); // create the invites foreach (var athlete in playersToInvite) { GameHostInvite invite = new GameHostInvite() { AthleteID = athlete.AthleteID, GameHost = gameHost, IsApprovedByHost = true, TimeCreated = DateTime.UtcNow }; db.GameHostInvites.Add(invite); } db.SaveChanges(); // add the comment if (string.IsNullOrEmpty(model.Comments) == false) { await new FeedLogic(db).MakeComment(me.AthleteID, NewsfeedItemTypeEnum.GameHost, gameHost.GameHostID, model.Comments, false); } // send the invites foreach (var athlete in playersToInvite) { await sendAnInvite(me, athlete, gameHost, venue, model.Comments); } return gameHost.GameHostID; }