public void Create(UserTeam userTeam) { userTeam.Created = DateTime.Now; userTeam.Modified = DateTime.Now; //using (var db = new DocumentStore() { Url = ConfigurationManager.AppSettings["dbUrl"], DefaultDatabase = ConfigurationManager.AppSettings["defaultDb"] }) //{ // db.Initialize(); // using (var session = db.OpenSession()) // { // session.Store(userTeam); // session.SaveChanges(); // } //} using (var db = new Pb.Dal.EfEntities()) { var insertme = new Pb.Dal.UserTeam() { Id = userTeam.Id == Guid.Empty ? Guid.NewGuid() : userTeam.Id, UserId = userTeam.UserId, TeamId = userTeam.TeamId, Created = userTeam.Created, Modified = userTeam.Modified, Deleted = userTeam.Deleted, Default = userTeam.Default }; db.UserTeams.Add(insertme); db.SaveChanges(); } }
//<name> <acronym> <description> public static string Execute(string[] data) { Check.CheckCreateTeamCommandLength(2, 3, data); //login first AuthenticationManager.Autorized(); var currentUser = AuthenticationManager.GetCurrentUser(); string teamName = data[0]; if (CommandHelper.IsTeamExisting(teamName)) { string errorMsg = string.Format(Constants.ErrorMessages.TeamExists, teamName); throw new ArgumentException(errorMsg); } string acronym = data[1]; if (acronym.Length != 3) { string errorMsg = string.Format(Constants.ErrorMessages.InvalidAcronym, acronym); throw new ArgumentException(errorMsg); } string description = data.Length == 3 ? data[2] : null; var team = new Team { Name = teamName, Description = description, Acronym = acronym, CreatorId = currentUser.UserId }; var usersInTeam = new UserTeam { Team = team, UserId = currentUser.UserId }; using (var db = new TeamBuilderContext()) { db.Teams.Add(team); db.UsersTeams.Add(usersInTeam); db.SaveChanges(); } return($"Team {teamName} successfully created!"); }
public TeamModel GetTeamModel(String name, Boolean withMembers = false, String viewUser = null) { var team = User.FindByName(name); if (team == null) { return(null); } var model = new TeamModel { Name = team.Name, Nickname = team.NickName, Description = team.Description, }; if (withMembers) { var list = UserTeam.FindAllByTeamID(team.ID).ToList().Where(e => e.User != null).ToList(); model.MembersRole = list .Select(s => new TeamModel.UserRole { Name = s.User.Name, NickName = s.User.NickName, IsAdministrator = s.IsAdmin }) .OrderBy(s => s.Name, new StringLogicalComparer()) .ToArray(); model.Members = list.ToDictionary(e => e.User.Name, e => e.User.NickName); var rs = team.Repositories.Where(e => e.Repository.Enable).ToList(); if (!viewUser.IsNullOrEmpty()) { var vu = User.FindByName(viewUser); rs = rs.Where(e => e.Repository.CanViewFor(vu)).ToList(); } model.RepositoriesRole = rs.Select(s => new TeamModel.RepositoryRole { Name = s.RepositoryName, AllowRead = s.AllowRead, AllowWrite = s.AllowWrite, }) .OrderBy(s => s.Name, new StringLogicalComparer()) .ToArray(); model.Repositories = rs .Select(s => s.Repository.Owner.Name + "@" + s.Repository.Name) .ToArray(); } return(model); }
public void StopFollowingTeam(int userId, int teamId) { UserTeam userTeamToDelete = unitOfWork.UserTeamRepository.Get(u => u.UserId == userId && u.TeamId == teamId).FirstOrDefault(); if (userTeamToDelete != null) { unitOfWork.UserTeamRepository.Delete(userTeamToDelete); unitOfWork.Save(); } else { throw new ArgumentException("El usuario no sigue al equipo. Verifique los datos ingresados"); } }
public IHttpActionResult DeleteUserTeam(Guid id) { UserTeam userTeam = db.UserTeams.Find(id); if (userTeam == null) { return(NotFound()); } db.UserTeams.Remove(userTeam); db.SaveChanges(); return(Ok(userTeam)); }
private void CreateUserTeam(string teamname) { using (var context = new FifaContext()) { var userTeam = new UserTeam { TeamName = teamname, TeamMoney = 10000000, UserTeamPlayers = new List <UserTeamPlayer>() }; context.UserTeams.Add(userTeam); context.SaveChanges(); } }
public string Execute(string[] arguments) { int argsCount = arguments.Length; if (argsCount != 2) { throw new FormatException(Constants.ErrorMessages.InvalidArgumentsCount); } this.authenticationManager.Authorize(); User currentUser = this.authenticationManager.GetCurrentUser(); string teamName = arguments[0]; string username = arguments[1]; if (!CommandHelper.IsUserCreatorOfTeam(teamName, currentUser)) { 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 (currentUser.Username == username) { throw new InvalidOperationException("Command not allowed. Use DisbandTeam instead."); } User kickUser = this.context.Users.FirstOrDefault(u => u.Username == username); Team team = this.context.Teams.FirstOrDefault(t => t.Name == teamName); UserTeam userTeam = this.context.UserTeams.FirstOrDefault(ut => ut.Team == team && ut.User == kickUser); this.context.UserTeams.Remove(userTeam); this.context.SaveChanges(); return($"User {username} was kicked from {teamName}!"); }
public void AcceptTeam([FromBody] AnswerTeamInputModel model) { var currentUser = _userDb.Users.FirstOrDefault(u => u.Id == _userManager.GetUserId(HttpContext.User)); var notification = _db.Notifications.FirstOrDefault(n => n.Id == model.NoteId); var team = _db.Teams.FirstOrDefault(t => t.Id == notification.ToTeamId); if (team == null) { return; } if (notification == null) { return; } if (currentUser == null) { return; } var userTeam = new UserTeam { TeamId = notification.ToTeamId, UserId = currentUser.Id, IsAdmin = false }; _db.UserTeams.Add(userTeam); _db.SaveChanges(); notification.IsRead = true; notification.ReadAt = DateTime.Now; notification.Message = "You have accepted the invitation to join " + team.Name; _db.SaveChanges(); var newNotification = new Notification { ToId = notification.FromId, ToName = notification.FromName, Message = "@" + notification.ToName + " has accepted the invitation to join your team.", FromId = currentUser.Id, FromName = currentUser.UserName, IsRead = false, ToTeamId = notification.ToTeamId, CreatedAt = DateTime.Now, Type = 2, Link = notification.Link }; _db.Notifications.Add(newNotification); _db.SaveChanges(); }
public AddTeamViewModel(UserTeam userTeamToRestore) : this() { this.Id = userTeamToRestore.Id; this.TeamName = userTeamToRestore.TeamName; this.TotalCans = userTeamToRestore.Cans; this.Sponsor = new SelectSponsorViewModel(this, userTeamToRestore.Sponsor); foreach (var v in userTeamToRestore.Vehicles) { var vm = new AddVehicleViewModel(this, v); this.Vehicles.Add(vm); } }
public void Update(UserTeamViewModel vmUserTeam, string UserName) { UserTeam objUserTeam = Find(vmUserTeam.UserTeamId); objUserTeam.User = vmUserTeam.User; objUserTeam.ProjectId = vmUserTeam.ProjectId; objUserTeam.Srl = vmUserTeam.Srl; objUserTeam.TeamUser = vmUserTeam.TeamUser; objUserTeam.ModifiedDate = DateTime.Now; objUserTeam.ModifiedBy = UserName; objUserTeam.ObjectState = ObjectState.Modified; _UserTeamRepository.Update(objUserTeam); _uniOfWork.Save(); }
private async Task Given_the_user_is_inside_of_a_team_and_there_exists_list_of_channels_in_database() { channels = DataGenerator.GenerateChannelList(config.Context, createTeamResult.BodyJson <Team>().Id, 10).ToList(); foreach (var c in channels) { createNewChannelResult = await helper.CreateChannelResponse(c, loginResult.Body.DeserializeJson <LoginResponse>().User.Id, loginResult.BodyJson <LoginResponse>().Token); } role = DataGenerator.GenerateSigleRole(config.Context, "AnyRole"); userRole = DataGenerator.GenerateSigleUserRole(config.Context, team.Id, user.Id, role.Id); }
private void KickMember(string teamName, string username) { using (var context = new TeamBuilderContext()) { int userId = context.Users.Single(u => u.Username == username).Id; int teamId = context.Teams.Single(t => t.Name == teamName).Id; UserTeam userTeam = context.UserTeams .Single(ut => ut.UserId == userId && ut.TeamId == teamId); context.UserTeams.Remove(userTeam); context.SaveChanges(); } }
public string Execute(string[] args) { Check.CheckLength(2, args); AuthenticationManager.Authorize(); User currentUser = AuthenticationManager.GetCurrentUser(); string teamName = args[0]; string username = args[1]; if (username == currentUser.Username) { throw new InvalidOperationException(string.Format(Constants.ErrorMessages.CommandNotAllowed, "DisbandTeam")); } else if (!CommandHelper.IsUserCreatorOfTeam(teamName, currentUser)) { throw new InvalidOperationException(Constants.ErrorMessages.NotAllowed); } else if (!CommandHelper.IsUserExisting(username)) { throw new ArgumentException(string.Format(Constants.ErrorMessages.UserNotFound, username)); } else if (!CommandHelper.IsTeamExisting(teamName)) { throw new ArgumentException(string.Format(Constants.ErrorMessages.TeamNotFound, teamName)); } else if (!CommandHelper.IsMemberOfTeam(teamName, username)) { throw new ArgumentException($"User {username} is not a member in {teamName}!"); } using (var context = new TeamBuilderContext()) { User userToKick = context.Users.FirstOrDefault(u => u.Username == username); Team fromTeamToKick = context.Teams.FirstOrDefault(t => t.Name == teamName); UserTeam userTeam = context.Teams .Include(t => t.UserTeams) .FirstOrDefault(t => t.Name == teamName) .UserTeams.FirstOrDefault(ut => ut.Team.Name == teamName); userToKick.UserTeams.Remove(userTeam); fromTeamToKick.UserTeams.Remove(userTeam); context.SaveChanges(); } return($"User {username} was kicked from {teamName}!"); }
public UserTeam NewUserTeam(UserTeam userTeam) { using (SqlConnection connection = DatabaseConnection.OpenConnection()) { string query = "INSERT INTO UserTeam (UserId) VALUES (@UserId)"; using (SqlCommand command = new SqlCommand(query, connection)) { command.Parameters.AddWithValue("@UserId", userTeam.userID); if (command.ExecuteNonQuery() == 1) { } } } return(userTeam); }
public async Task <ActionResult <Team> > PostTeam(Team team) { team.ImagePath = "https://soccercastpictures.blob.core.windows.net/firstcontainer/blank-team-picture.jpg"; _context.Teams.Add(team); await _context.SaveChangesAsync(); UserTeam userTeam = new UserTeam(); userTeam.TeamID = team.TeamID; userTeam.UserID = team.CaptainID; userTeam.UserTeamStatusID = 1; _context.UserTeam.Add(userTeam); await _context.SaveChangesAsync(); return(Ok(team)); }
public AddUserToTeamResponseModel DeleteUserService(Guid id) { try { UserTeam userTeam = UnitOfWork.GetRepository <UserTeam>().Single(p => p.Id == id); if (userTeam == null) { userteamResponse = new AddUserToTeamResponseModel() { userTeam = null, Message = "Entity Does Not Exist", code = responseCode.ErrorOccured }; return(userteamResponse); } else { if (userTeam.Status == EntityStatus.Active) { userTeam.Status = EntityStatus.InActive; UnitOfWork.GetRepository <UserTeam>().Update(userTeam); UnitOfWork.SaveChanges(); //Audit Logger _iauditExtension.Auditlogger(userTeam.Company_Id, userTeam.User_Id, "You were removed from a team"); userteamResponse = new AddUserToTeamResponseModel() { userTeam = userTeam, Message = "Entity Deleted Successfully", code = responseCode.Successful }; return(userteamResponse); } else { userteamResponse = new AddUserToTeamResponseModel() { userTeam = null, Message = "Entity Does Not Exist", code = responseCode.ErrorOccured }; return(userteamResponse); } } } catch (Exception ex) { _loggerManager.LogError(ex.Message); throw; } }
public async Task <ActionResult <TeamDTO> > CreateTeam(CreateTeamDTO createTeamDto) { if (await TeamExists(createTeamDto.TeamName)) { return(BadRequest("That team already exist")); } var team = new UserTeam(); team.TeamName = createTeamDto.TeamName.ToUpper(); _teamRepository.add(team); return(new TeamDTO { TeamName = createTeamDto.TeamName }); }
private async Task <dynamic> AddUserAsync(dynamic parameters, CancellationToken cancellationToken) { var request = this.Bind <AssignRoleRequest>(); var userRole = new UserTeam { RoleId = request.RoleId, TeamId = request.TeamId, UserId = request.UserId }; context.UserTeams.Add(userRole); await context.SaveChangesAsync(cancellationToken).ConfigureAwait(false); return(Response.AsJson(userRole)); }
public GameControllerTest() { // autofixture automatically creates objects _fixture = new Fixture(); _fixture.Behaviors.Remove(new ThrowingRecursionBehavior()); _fixture.Behaviors.Add(new OmitOnRecursionBehavior(1)); //Recursion of 1 _creator = _fixture.Create <UserProfile>(); _user = _fixture.Create <UserProfile>(); _game = _fixture.Create <Game>(); _uteams = new HashSet <UserTeam>(); _ut = _fixture.Create <UserTeam>(); _utp = null; _games = _fixture.Create <List <Game> >(); _userteams = _fixture.Create <List <UserTeam> >(); _mockServiceLayer = new Mock <IService>(); }
// GET: api/QUserTeams/5 public List <UserTeam> Get(int?id) { List <UserTeam> UserTeamList = new List <UserTeam>(); if (id == null) { return(null); } UserTeam @UserTeam = db.UserTeams.Find(id); if (@UserTeam == null) { return(null); } UserTeamList.Add(@UserTeam); return(UserTeamList); }
//<teamName> public static string Execute(string[] data) { Check.CheckLenght(1, data); //login first AuthenticationManager.Autorized(); var currentUser = AuthenticationManager.GetCurrentUser(); string teamName = data[0]; bool isTeamExist = CommandHelper.IsTeamExisting(teamName); if (!isTeamExist) { string errorMsg = string.Format(Constants.ErrorMessages.TeamNotFound, teamName); throw new ArgumentException(errorMsg); } bool isInviteExist = CommandHelper.IsInviteExisting(teamName, currentUser); if (!isInviteExist) { string errorMsg = string.Format(Constants.ErrorMessages.InviteNotFound, teamName); throw new ArgumentException(errorMsg); } using (var db = new TeamBuilderContext()) { var currentInvitation = db.Invitations .FirstOrDefault(i => i.Team.Name == teamName && i.InvitedUserId == currentUser.UserId && i.IsActive); currentInvitation.IsActive = false; var team = db.Teams.FirstOrDefault(t => t.Name == teamName); var addUserToTeam = new UserTeam { TeamId = team.TeamId, UserId = currentUser.UserId }; db.UsersTeams.Add(addUserToTeam); db.SaveChanges(); } return($"User {currentUser.Username} joined team {teamName}!"); }
public void AcceptInvitation(string teamName) { var Invitation = AuthenticationService.GetCurrentUser().ReceivedInvitations .Where(i => i.IsActive == true) .FirstOrDefault(i => i.Team.Name == teamName); var userTeam = new UserTeam { TeamId = this.context.Teams.FirstOrDefault(t => t.Id == Invitation.TeamId).Id, UserId = this.context.Users.FirstOrDefault(u => u.Id == Invitation.InvitedUserId).Id }; this.context.Teams.FirstOrDefault(t => t.Name == Invitation.Team.Name).UserTeams.Add(userTeam); this.context.Invitations.FirstOrDefault(i => i.Id == Invitation.Id).IsActive = false; this.context.SaveChanges(); }
public void CheckExistingTeamTest() { //Arrange var model = new UserTeam() { TournamentId = "UniqueTournamentId", TeamName = "TeamName", TeamId = "UniqueTeamId" }; var val = _service.CreateWithId(model.TournamentId, model).Result; //Act var teams = _service.ExistingUserTeams; //Assert teams.Should().NotBeNull(); teams.First().Should().BeEquivalentTo(model); }
private void AcceptInvite(User currentUser, string teamName) { using (TeamBuilderContext context = new TeamBuilderContext()) { var teamId = context.Teams.FirstOrDefault(e => e.Name == teamName).Id; var userTeam = new UserTeam() { UserId = currentUser.Id, TeamId = teamId }; var invite = context.Invitations.FirstOrDefault(e => e.InvitedUserId == currentUser.Id && e.TeamId == teamId); invite.IsActive = false; context.UserTeams.Add(userTeam); context.SaveChanges(); } }
public UserTeamViewModel Create(UserTeamViewModel vmUserTeams, string UserName) { UserTeam objUserTeam = new UserTeam(); objUserTeam = Mapper.Map <UserTeam>(vmUserTeams); objUserTeam.ModifiedBy = UserName; objUserTeam.CreatedBy = UserName; objUserTeam.CreatedDate = DateTime.Now; objUserTeam.ModifiedDate = DateTime.Now; objUserTeam.ObjectState = ObjectState.Added; _UserTeamRepository.Add(objUserTeam); _uniOfWork.Save(); vmUserTeams.UserTeamId = objUserTeam.UserTeamId; return(vmUserTeams); }
void ExecuteSaveAsync() { var t = this; var team = new UserTeam { Id = t.Id, TeamName = t.TeamName, Cans = t.TotalCans, Sponsor = t.Sponsor.SelectedSponsor, Vehicles = t.Vehicles.Select(v => new UserVehicle { VehicleName = v.Name, VehicleType = v.SelectedVehicleType, Trailers = v.Trailers.Select(tr => tr.GetModel()).ToList(), Weaposn = v.Weapons.Select(x => x.GetModel()).ToList(), Perks = v.Perks.Select(x => x.GetModel()).ToList(), Upgrades = v.Upgrades.Select(x => x.GetModel()).ToList() }).ToList() }; List <UserTeam> teamList = null; var currentJson = Xamarin.Essentials.Preferences.Get("TEAMDATA", (string)null); if (!string.IsNullOrEmpty(currentJson)) { teamList = JsonConvert.DeserializeObject <List <UserTeam> >(currentJson); } else { teamList = new List <UserTeam>(); } teamList.Add(team); var newjson = JsonConvert.SerializeObject(teamList); Xamarin.Essentials.Preferences.Set("TEAMDATA", newjson); MessagingCenter.Send(this, "TEAMSAVED"); DependencyService.Get <INavigationService>().Dismiss(this); }
public void AddUserToGame(int userId, int gameId) { try { UserTeam ut = null; if (!_userTeams.TryGet(out ut, x => x.GameId == gameId && x.UserId == userId)) { _userTeams.Create(new UserTeam() { UserId = userId, GameId = gameId }); } Save(); } catch (Exception _exp) { OperationStatus.CreateFromException(String.Format("AddUserToGame failed. userId:{0}, gameId:{1}", userId, gameId), _exp, true); throw; } }
public Boolean InTeam(String teamname, String username) { var team = User.FindByName(teamname); if (team == null) { return(false); } var user = User.FindByName(username); if (user == null) { return(false); } var tu = UserTeam.FindByUserIDAndTeamID(user.ID, team.ID); return(tu != null); }
public static UserTeamModel MapUserTeamEntityToUserTeamModel(UserTeam entity) { if (entity == null) { return(null); } var teamId = entity.TeamId; var team = MapTeamEntityToTeamModelBase(entity.Team); var userId = entity.UserId; var user = MapUserEntityToUserModelBase(entity.User); return(new UserTeamModel { TeamId = teamId, Team = team, UserId = userId, User = user }); }
private void AcceptInvite(User currentUser, string teamName) { using (var context = new TeamBuilderContext()) { int teamId = context.Teams.Single(t => t.Name == teamName).Id; var userTeam = new UserTeam { UserId = currentUser.Id, TeamId = teamId }; context.UserTeams.Add(userTeam); context.Invitations .Single(i => i.InvitedUserId == currentUser.Id && i.TeamId == teamId) .IsActive = false; context.SaveChanges(); } }
public async Task UpdateUserTeamAsync_UserTeamHasLessThan11Starters_ReturnsException() { //arrange var userTeam = new UserTeam { ID = "1", UserPlayFabID = fakePlayFabService.PlayFabId, MatchdayScores = new Dictionary <int, int> { }, Players = DataHelper.GetDummyPlayers(1, 1) }; //act async Task actual() { await fantasySoccerService.UpdateUserTeamAsync(userTeam); } //assert await Assert.ThrowsAsync <Exception>(actual); }