Exemple #1
0
        public string Execute(string[] args)
        {
            Check.CheckLength(6, args);
            _authManager.Authorizer();

            User user = this._authManager.GetCurrenUser();

            var eventName = args[0];

            CheckEventName(eventName);

            var eventDescription = args[1];

            CheckEventDescription(eventDescription);

            string   fullStartDate = $"{args[2]} {args[3]}";
            DateTime startDate;
            bool     isStartDateValid = DateTime
                                        .TryParseExact(fullStartDate, Constants.DateTimeFormat, CultureInfo.InvariantCulture, DateTimeStyles.None, out startDate);

            string   fullEndDate = $"{args[4]} {args[5]}";
            DateTime endDate;
            bool     isEndDateValid = DateTime
                                      .TryParseExact(fullEndDate, Constants.DateTimeFormat, CultureInfo.InvariantCulture, DateTimeStyles.None, out endDate);

            if (!isStartDateValid || !isEndDateValid)
            {
                throw new ArgumentException(Constants.ErrorMessages.InvalidDateFormat);
            }

            AddEventToDb(user, eventName, eventDescription, startDate, endDate);

            return($"Event {eventName} was created successfully!");
        }
        public string Execute(string[] args)
        {
            int argsCount = args.Length;

            if (argsCount < 2 || argsCount > 3)
            {
                throw new FormatException(Constants.ErrorMessages.InvalidArgumentsCount);
            }

            _authManager.Authorizer();

            var user = _authManager.GetCurrenUser();

            string teamName = args[0];

            CheckTeamName(teamName);

            string acronym = args[1];

            CheckAcronym(acronym);

            string description = null;

            if (argsCount == 3)
            {
                description = args[2];
                CheckDescription(description);
            }

            AddTeamToDb(user.Id, teamName, acronym, description);

            return($"Team {teamName} successfully created!");
        }
        public string Execute(string[] args)
        {
            Check.CheckLength(1, args);
            _authManager.Authorizer();

            var    user     = _authManager.GetCurrenUser();
            string teamName = args[0];

            CheckTeamInvite(teamName, user);

            AcceptInvite(teamName, user);

            return($"User {user.Username} joined team {teamName}!");
        }
        public string Execute(string[] args)
        {
            Check.CheckLength(1, args);
            _authManager.Authorizer();

            var    user     = _authManager.GetCurrenUser();
            string teamName = args[0];

            CheckTeamInvite(teamName, user);

            DeclineInvite(teamName, user);

            return($"Invite from {teamName} declined.");
        }
Exemple #5
0
        public string Execute(string[] args)
        {
            Check.CheckLength(2, args);
            _authManager.Authorizer();

            var    user      = _authManager.GetCurrenUser();
            string eventName = args[0];
            string teamName  = args[1];

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

            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));
            }

            Event eventa = null;
            Team  team   = null;

            using (var context = new TeamBuilderContext())
            {
                eventa = context.Events
                         .Where(e => e.Name == eventName)
                         .OrderBy(e => e.StartDate)
                         .Last();

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

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

                context.TeamEvents.Add(new TeamEvent()
                {
                    Event = eventa, Team = team
                });
                context.SaveChanges();
            }

            return($"Team {teamName} added for {eventName}!");
        }
        public string Execute(string[] args)
        {
            Check.CheckLength(2, args);
            _authManager.Authorizer();

            var    user     = _authManager.GetCurrenUser();
            string teamName = args[0];
            string username = args[1];

            if (!CommandHelper.IsUserCreatorOfTeam(teamName, user))
            {
                throw new InvalidOperationException(Constants.ErrorMessages.NotAllowed);
            }

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

            if (!CommandHelper.IsUserExisting(username))
            {
                throw new ArgumentException(String.Format(Constants.ErrorMessages.UserNotFound, username));
            }

            if (!CommandHelper.IsMemberOfTeam(teamName, username))
            {
                throw new ArgumentException(String.Format(Constants.ErrorMessages.NotPartOfTeam, username, teamName));
            }

            if (user.Username == username)
            {
                throw new InvalidOperationException("Command not allowed. Use DisbandTeam instead.");
            }

            using (var context = new TeamBuilderContext())
            {
                var userToBeKicked = context.Users.SingleOrDefault(u => u.Username == username);
                var team           = context.Teams.SingleOrDefault(t => t.Name == teamName);
                var userTeam       = context.UserTeams.SingleOrDefault(ut => ut.Team == team && ut.User == userToBeKicked);

                context.UserTeams.Remove(userTeam);
                context.SaveChanges();
            }

            return($"User {username} was kicked from {teamName}!");
        }
Exemple #7
0
        public string Execute(string[] args)
        {
            Check.CheckLength(1, args);
            _authManager.Authorizer();

            var user = _authManager.GetCurrenUser();

            var teamName = args[0];

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

            if (!CommandHelper.IsUserCreatorOfTeam(teamName, user))
            {
                throw new InvalidOperationException(Constants.ErrorMessages.NotAllowed);
            }

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

                var eventTeams  = context.TeamEvents.Where(et => et.Team == team);
                var userTeams   = context.UserTeams.Where(ut => ut.Team == team);
                var invitations = context.Invitations.Where(i => i.Team == team);

                context.TeamEvents.RemoveRange(eventTeams);
                context.UserTeams.RemoveRange(userTeams);
                context.Invitations.RemoveRange(invitations);

                context.Teams.Remove(team);

                context.SaveChanges();
            }

            return($"{teamName} has disbanded!");
        }