public void DeleteUser(int userId)
        {
            User user = dbContext.Users.Find(userId);

            user.IsDeleted = true;
            dbContext.SaveChanges();
        }
        public void AddMember(int teamId, int userId)
        {
            UserTeam membership = new UserTeam()
            {
                UserId = userId,
                TeamId = teamId
            };

            dbContext.UserTeams.Add(membership);
            dbContext.SaveChanges();
        }
Beispiel #3
0
        public void AddInvitation(int teamId, int userId)
        {
            Invitation invitation = new Invitation()
            {
                TeamId        = teamId,
                InvitedUserId = userId,
                IsActive      = true
            };

            dbContext.Invitations.Add(invitation);
            dbContext.SaveChanges();
        }
Beispiel #4
0
        public void InviteToTeam(string teamName, string userName)
        {
            var team = context.Teams.FirstOrDefault(t => t.Name == teamName);
            var user = context.Users.FirstOrDefault(u => u.Username == userName);

            var invitation = new Invitation()
            {
                InvitedUserId = user.Id,
                TeamId        = team.Id
            };

            context.Invitations.Add(invitation);
            context.SaveChanges();
        }
Beispiel #5
0
        public Team Create(string name, string acronym, string description, int creatorId)
        {
            var team = new Team()
            {
                Name        = name,
                Acronym     = acronym,
                Description = description,
                CreatorId   = creatorId
            };

            context.Teams.Add(team);
            context.SaveChanges();

            return(team);
        }
Beispiel #6
0
        public string Execute(params string[] args)
        {
            Check.CheckLength(2, args);

            var teamName = args[0];
            var username = args[1];

            using (var context = new TeamBuilderDbContext())
            {
                var team = context.Teams.SingleOrDefault(t => t.Name == teamName);
                var user = context.Users.SingleOrDefault(u => u.Username == username);

                if (team == null || user == null)
                {
                    throw new ArgumentException(Constants.ErrorMessages.TeamOrUserNotExist);
                }

                if (Session.User == null)
                {
                    throw new InvalidOperationException(Constants.ErrorMessages.LoginFirst);
                }

                var isCreator       = CommandHelper.IsUserCreatorOfTeam(teamName, user);
                var isAlreadyInTeam = CommandHelper.IsMemberOfTeam(teamName, username);

                if (isCreator)
                {
                    var userTeam = new UserTeam()
                    {
                        Team = team,
                        User = user
                    };

                    user.CreatedUserTeams.Add(userTeam);
                    team.Members.Add(userTeam);
                    context.UserTeams.Add(userTeam);
                    context.SaveChanges();

                    return($"Team {teamName} invited {username}!");
                }

                if (isCreator || isAlreadyInTeam)
                {
                    throw new InvalidOperationException(Constants.ErrorMessages.NotAllowed);
                }

                var invitation = context.Invitations.Where(i => i.TeamId == team.Id && i.InvitedUserId == user.Id && i.IsActive == true);

                if (invitation.Any())
                {
                    throw new InvalidOperationException(Constants.ErrorMessages.InviteIsAlreadySent);
                }
            }

            invitationService.InviteToTeam(teamName, username);

            return($"Team {teamName} invited {username}!");
        }
Beispiel #7
0
        public void Delete(int id)
        {
            using (var context = new TeamBuilderDbContext())
            {
                var user = context.Users.Find(id);

                context.Users.Remove(user);
                context.SaveChanges();
            }
        }
Beispiel #8
0
        public Event Create(string name, string description, DateTime startDate, DateTime endDate, int creatorId)
        {
            var user = context.Users.FirstOrDefault(u => u.Id == creatorId);

            var newEvent = new Event()
            {
                Name        = name,
                Description = description,
                StartDate   = startDate,
                EndDate     = endDate,
                CreatorId   = creatorId
            };

            user.CreatedEvents.Add(newEvent);
            context.Events.Add(newEvent);
            context.SaveChanges();

            return(newEvent);
        }
Beispiel #9
0
        public User Create(string username, string password, string firstName, string lastName, int age, Gender gender)
        {
            using (var context = new TeamBuilderDbContext())
            {
                var user = new User()
                {
                    Username  = username,
                    Password  = password,
                    FirstName = firstName,
                    LastName  = lastName,
                    Age       = age,
                    Gender    = gender
                };

                context.Users.Add(user);
                context.SaveChanges();

                return(user);
            }
        }