Ejemplo n.º 1
0
        public void AddEventTeam(Event @event, Team team)
        {
            TeamEvent teamEvent = new TeamEvent
            {
                Event = @event,
                Team  = team
            };

            this.context.TeamEvents.Add(teamEvent);

            this.context.SaveChanges();
        }
Ejemplo n.º 2
0
        public void AddTeamTo(string eventName, string teamName)
        {
            var team      = context.Teams.SingleOrDefault(p => p.Name == teamName);
            var @event    = context.Events.Where(p => p.Name == eventName).OrderByDescending(p => p.StartDate).First();
            var teamEvent = new TeamEvent
            {
                Team  = team,
                Event = @event
            };

            context.TeamEvents.Add(teamEvent);
            context.SaveChanges();
        }
Ejemplo n.º 3
0
        //<eventName> <teamName>
        public static string Execute(string[] data)
        {
            Check.CheckLenght(2, data);

            AuthenticationManager.Autorized();
            var currentUser = AuthenticationManager.GetCurrentUser();

            string eventName = data[0];
            string teamName  = data[1];

            if (!CommandHelper.IsEventExisting(eventName))
            {
                string errorMsg = string.Format(Constants.ErrorMessages.EventNotFound, eventName);
                throw new ArgumentException(errorMsg);
            }

            if (!CommandHelper.IsTeamExisting(teamName))
            {
                string errorMsg = string.Format(Constants.ErrorMessages.TeamNotFound, teamName);
                throw new ArgumentException(errorMsg);
            }

            if (!CommandHelper.IsUserCreatorOfEvent(eventName, currentUser))
            {
                throw new InvalidOperationException(Constants.ErrorMessages.NotAllowed);
            }

            var currentEvent = CommandHelper.GetLatestEvent(eventName);

            using (var db = new TeamBuilderContext())
            {
                var team = db.Teams.SingleOrDefault(t => t.Name == teamName);

                bool isTeamAddedToEvent = db.TeamsEvents.Any(te => te.EventId == currentEvent.EventId && te.TeamId == team.TeamId);

                if (isTeamAddedToEvent)
                {
                    throw new InvalidOperationException(Constants.ErrorMessages.CannotAddSameTeamTwice);
                }

                var teamToAddToEvent = new TeamEvent
                {
                    TeamId  = team.TeamId,
                    EventId = currentEvent.EventId
                };

                db.TeamsEvents.Add(teamToAddToEvent);
                db.SaveChanges();
            }
            return($"Team {teamName} added for {eventName}!");
        }
        public void AddTeamToEvent(string eventName, string teamName)
        {
            var eventId = this.context.Events.OrderBy(e => e.StartDate).FirstOrDefault(e => e.Name == eventName).Id;
            var teamId  = this.context.Teams.FirstOrDefault(t => t.Name == teamName).Id;

            var eventTeam = new TeamEvent
            {
                EventId = eventId,
                TeamId  = teamId
            };

            this.context.Events.FirstOrDefault(e => e.Name == eventName).ParticipatingEventTeams.Add(eventTeam);
            this.context.SaveChanges();
        }
        public string Execute(string[] args)
        {
            Check.CheckLenght(2, args);
            var eventName = args[0];
            var teamName  = args[1];

            AuthenticationManager.Authorize();

            if (!CommandHelper.IsEventExisting(eventName))
            {
                throw new ArgumentException(string.Format(Constants.ErrorMessages.EventNotFound, eventName));
            }

            if (!CommandHelper.IsTeamExisting(teamName))
            {
                throw new ArgumentException(string.Format(Constants.ErrorMessages.TeamNotFound, teamName));
            }

            var currentUser = AuthenticationManager.GetCurrentUser();

            if (!CommandHelper.IsUserCreatorOfEvent(eventName, currentUser))
            {
                throw new InvalidOperationException(Constants.ErrorMessages.NotAllowed);
            }

            if (CommandHelper.IsTeamAddedToEvent(eventName, teamName))
            {
                throw new InvalidOperationException(Constants.ErrorMessages.CannotAddSameTeamTwice);
            }

            using (var context = new TeamBuilderContext())
            {
                var eventt = context.Events
                             .Where(e => e.Name == eventName)
                             .OrderByDescending(e => e.StartDate)
                             .FirstOrDefault();
                var team = context.Teams.FirstOrDefault(t => t.Name == teamName);

                var teamEvent = new TeamEvent
                {
                    Event = eventt,
                    Team  = team
                };

                eventt.ParticipatingTeams.Add(teamEvent);
                context.SaveChanges();
            }

            return(string.Format(Constants.SuccessMessages.AddTeamTo, teamName, eventName));
        }
Ejemplo n.º 6
0
        public static void CreateTeamEvent(TeamEvent eventData, Action <SingleTeamEventResponse> onComplete)
        {
            //POST /api/teams/members/:teamId
            Dictionary <string, object> body = new Dictionary <string, object>()
            {
                { "name", eventData.name },
                { "details", eventData.details },
                { "location", eventData.location },
                { "startDate", eventData.startDate },
                { "endDate", eventData.endDate },
                { "allDayEvent", eventData.allDayEvent },
                { "team", eventData.team }
            };


            ServerRequest.CallAPI("/teams/events/create", HTTPMethod.POST, body, (r) => { ServerRequest.ResponseHandler(r, null, onComplete); }, true);
        }
Ejemplo n.º 7
0
        public async Task <ActionResult> PostTeamEvent(TeamEventCreateRequest request)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }

            var utcNow = DateTime.UtcNow;
            var userId = User.FindFirst(ClaimTypes.NameIdentifier).Value;
            var owner  = await _userManager.FindByIdAsync(userId);

            var startDate = Convert.ToDateTime(request.StartDate).Date
                            .AddHours(request.StartTime.GetProperty("hour").GetUInt32())
                            .AddMinutes(request.StartTime.GetProperty("minute").GetUInt32());

            var teamEvent = new TeamEvent
            {
                Name             = request.Name,
                Location         = request.Location,
                Description      = request.Description,
                LocationMapUrl   = request.LocationMapUrl,
                Categories       = request.Categories,
                TicketPrice      = request.TicketPrice,
                MaxAttendees     = request.MaxAttendees,
                MinAttendees     = request.MinAttendees,
                LogoImageUrl     = request.LogoImageUrl,
                LocationImageUrl = request.LocationImageUrl,
                Status           = request.Status,
                CreateDate       = utcNow,
                LastModifiedDate = utcNow,
                StartDate        = startDate,
                Owner            = owner.Email,
                Attendees        = "[]",
                Photos           = "[]",
                Comments         = "[]",
                Reviews          = "[]"
            };

            _context.TeamEvents.Add(teamEvent);
            await _context.SaveChangesAsync();

            return(Created($"api/teamevents/{teamEvent.Id}", teamEvent));
        }
        private static void AddTeamTo(string eventName, string teamName)
        {
            using (var db = new TeamBuilderContext())
            {
                var events = db
                             .Events
                             .Where(e => e.Name == eventName)
                             .ToList();

                var eventId = default(int);

                if (events.Count > 1)
                {
                    DateTime?latestDate = events
                                          .Where(e => e.StartDate.HasValue)
                                          .Max(e => e.StartDate)
                                          .Value;

                    eventId = events
                              .Single(e => e.StartDate == latestDate)
                              .Id;
                }
                else
                {
                    eventId = events.First().Id;
                }

                var teamId = db
                             .Teams
                             .First(t => t.Name == teamName)
                             .Id;

                var currentTeamEvent = new TeamEvent()
                {
                    EventId = eventId,
                    TeamId  = teamId
                };

                db.TeamEvents.Add(currentTeamEvent);
                db.SaveChanges();
            }
        }
Ejemplo n.º 9
0
        // <eventName> <teamName>
        public override string Execute(TeamBuilderContext context)
        {
            base.MustBeLoggedIn();
            base.CmdArgsExactLengthValidation(ArgsExactLength);

            var eventName = this.CmdArgs[0];
            var teamName  = this.CmdArgs[1];

            var team   = this.GetTem(context, teamName);
            var @event = this.GetEvent(context, eventName, team);

            var mapping = new TeamEvent();

            mapping.Event = @event;
            mapping.Team  = team;

            context.TeamsEvents.Add(mapping);
            context.SaveChanges();

            return(string.Format(Success, teamName, eventName));
        }
Ejemplo n.º 10
0
        //•	AddTeamTo <eventName> <teamName>
        //Adds given team for event specified.If there are more than one events with same name pick the latest start date.

        public string AddTeamTo(string eventName, string teamName)
        {
            var teamToAdd    = db.Teams.SingleOrDefault(team => team.Name == teamName);
            var createdEvent = db.Events
                               .OrderByDescending(ev => ev.StartDate)
                               .FirstOrDefault(ev => ev.Name == eventName);

            var teamEvent = new TeamEvent()
            {
                TeamId  = teamToAdd.Id,
                EventId = createdEvent.Id
            };

            this.db.TeamEvents.Add(teamEvent);

            teamToAdd.ParticipatedEvents.Add(teamEvent);
            createdEvent.ParticipatingTeams.Add(teamEvent);
            db.SaveChanges();

            return($"Team {teamName} added for {eventName}!");
        }
Ejemplo n.º 11
0
        public static void UpdateTeamEvent(TeamEvent teamEvent, Action <SingleTeamEventResponse> onComplete)
        {
            //throw new System.NotImplementedException();
            //PUT /api/teams/members/:teamId

            Dictionary <string, object> body = new Dictionary <string, object>()
            {
                { "eventId", teamEvent._id },
                { "team", teamEvent.team },
                { "name", teamEvent.name },
                { "location", teamEvent.location },
                { "details", teamEvent.details },
                { "startDate", teamEvent.startDate },
                { "endDate", teamEvent.endDate },
                { "allDayEvent", teamEvent.allDayEvent },
                { "newInvites", teamEvent.newInvites },
                { "removeInvites", teamEvent.removeInvites }
            };

            ServerRequest.CallAPI("/teams/events/update", HTTPMethod.PUT, body, (r) => { ServerRequest.ResponseHandler(r, null, onComplete); }, true);
        }
        public void AddTeamTo(string eventName, string teamName)
        {
            Event eventa = null;
            Team  team   = null;

            eventa = this.context.Events
                     .Where(e => e.Name == eventName)
                     .OrderBy(e => e.StartDate)
                     .Last();

            team = this.context.Teams.FirstOrDefault(t => t.Name == teamName);

            if (this.context.EventTeams.Any(et => et.Team == team && et.Event == eventa))
            {
                throw new InvalidOperationException("Cannot add same team twice!");
            }

            var result = new TeamEvent(eventa, team);

            this.context.EventTeams.Add(result);
            this.context.SaveChanges();
        }
Ejemplo n.º 13
0
        public async Task BuildTextWithLinksAsync(TeamEvent teamEvent)
        {
            var input            = teamEvent.Description;
            var entitiesResponse = await _client.EntitiesAsync(input, "en");

            var keyPhrasesResponse = await _client.KeyPhrasesAsync(input, "en");

            var words = new SortedSet <string>();

            foreach (var entity in entitiesResponse.Entities)
            {
                words.Add($"{entity.Name}_{entity.Type.Replace("DateTime", "Date")}");
            }

            foreach (var keyPhrase in keyPhrasesResponse.KeyPhrases)
            {
                words.Add($"{keyPhrase}_Phrase");
            }

            var photos = new HashSet <dynamic>();

            foreach (var word in words)
            {
                var text = word.Split('_')[0];
                var type = word.Split('_')[1];

                using var httpClient = new HttpClient();
                var encodedEntity = HttpUtility.UrlEncode(text);

                var wikiResponseRaw = await httpClient.GetStringAsync(
                    $"{WikiSearchEndpoint}?action=opensearch&" +
                    $"search={encodedEntity}&" +
                    "limit=1&" +
                    "namespace=0&" +
                    "format=json");

                if (!string.IsNullOrEmpty(wikiResponseRaw))
                {
                    var wikiResponse = (JArray)JsonConvert.DeserializeObject(wikiResponseRaw);
                    if (wikiResponse.Count == 4)
                    {
                        var links = (JArray)wikiResponse[3];
                        if (links.Count == 1)
                        {
                            var link = ((JArray)wikiResponse[3])[0].Value <string>();
                            input = ReplaceWithLink(input, " ", text, link);
                            input = ReplaceWithLink(input, ", ", text, link);
                            input = ReplaceWithLink(input, ". ", text, link);

                            teamEvent.Description = input;

                            var wikiImageResponse = await httpClient.GetStringAsync(
                                $"{WikiSearchEndpoint}?action=query&" +
                                "prop=pageimages&" +
                                "formatversion=2&" +
                                "format=json&" +
                                "piprop=original&" +
                                $"titles={text}");

                            var imageUrl = ((JObject)JsonConvert.DeserializeObject(wikiImageResponse))
                                           .SelectToken("$.query.pages[0].original.source")?.Value <string>();

                            if (!string.IsNullOrEmpty(imageUrl))
                            {
                                photos.Add(new { imageUrl = imageUrl, title = text, link = link, type = type });
                            }
                        }
                    }
                }
            }

            teamEvent.Photos = JsonConvert.SerializeObject(photos);
        }
Ejemplo n.º 14
0
        private void On(TeamEvent e)
        {
            var p = e.Player;

            p.Team = e.Team;
        }
Ejemplo n.º 15
0
        private void OnTeam(TeamEvent e)
        {
            Player p = e.Player;

            p.Team = e.Team;
        }