Пример #1
0
        public async Task<int> NewGameHostInvite(NewGameHostInviteWebModel model)
        {
            int gameHostID = model.GameHostID;
            int athleteID = model.AthleteID;

            var me = new UserProfileLogic(db).GetAthleteForUserName(this.User.Identity.Name);
            var athlete = db.Athletes.Single(i => i.AthleteID == athleteID);
            if (athlete == null || me.AthleteID == athleteID)
                throw new Exception("athleteID is invalid");

            GameHost gameHost = db.GameHosts.Include("Venue").Single(i => i.GameHostID == gameHostID);
            if (gameHost.GameHostInvites.Where(i => i.AthleteID == athleteID).Count() > 0)
                throw new Exception("an invite for this athlete already exists");

            GameHostInvite invite = new GameHostInvite()
            {
                AthleteID = athleteID,
                GameHost = gameHost,
                IsApprovedByHost = true,
                TimeCreated = DateTime.UtcNow
            };
            db.GameHostInvites.Add(invite);
            db.SaveChanges();

            await sendAnInvite(me, athlete, gameHost, gameHost.Venue, "");

            return invite.GameHostInviteID;
        }
Пример #2
0
        public async Task <int?> NewGameHostInvite(int gameHostID, int athleteID, DateTime when_InLocalTimeZone)
        {
            string url = WebApiUrl + "GameHosts/NewGameHostInvite";

            try
            {
                NewGameHostInviteWebModel model = new NewGameHostInviteWebModel()
                {
                    GameHostID           = gameHostID,
                    AthleteID            = athleteID,
                    When_InLocalTimeZone = when_InLocalTimeZone
                };
                string json = await this.sendPostRequestAndReceiveResponse(url, true);

                int modelResponse = JsonConvert.DeserializeObject <int>(json);
                return(modelResponse);
            }
            catch (Exception exc)
            {
                LastExceptionUrl = url;
                LastException    = exc;
                return(null);
            }
        }