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(); }
public void AddInvitation(int teamId, int userId) { Invitation invitation = new Invitation() { TeamId = teamId, InvitedUserId = userId, IsActive = true }; dbContext.Invitations.Add(invitation); dbContext.SaveChanges(); }
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(); }
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); }
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}!"); }
public void Delete(int id) { using (var context = new TeamBuilderDbContext()) { var user = context.Users.Find(id); context.Users.Remove(user); context.SaveChanges(); } }
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); }
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); } }