Пример #1
0
        public async Task <ActionResult <TeamUser> > PostTeamUser(TeamUser teamUser)
        {
            _context.TeamUsers.Add(teamUser);
            await _context.SaveChangesAsync();

            return(teamUser);
        }
Пример #2
0
        public async Task <ResultData <RetrospectorUser> > RemoveUserFromTeamAsync(string userId, int teamId)
        {
            if (string.IsNullOrEmpty(userId))
            {
                return(new ResultData <RetrospectorUser>(UserIdNullMessage, false));
            }

            RetrospectorUser user = await _userRepository.GetUserWithTeamUsersAsync(userId);

            if (user == null)
            {
                return(new ResultData <RetrospectorUser>(UserEmailDoesntExistMessage, false));
            }

            Team team = await _teamsRepository.GetTeamByIdAsync(teamId);

            if (team == null)
            {
                return(new ResultData <RetrospectorUser>(TeamDoesntExistMessage, false));
            }

            TeamUser teamUser = await _teamsRepository.GetTeamUserAsync(user.Id, teamId);

            if (teamUser == null)
            {
                return(new ResultData <RetrospectorUser>(UserNotInTeamMessage, false));
            }

            user.TeamUsers = user.TeamUsers.Where(tu => tu.TeamId != teamId).ToList();
            await _userRepository.UpdateAsync(user);

            return(new ResultData <RetrospectorUser>(UsersAddedToTeamMessage, true, user));
        }
Пример #3
0
 public ActionResult NewTeam(Team team)
 {
     try
     {
         if (ModelState.IsValid)
         {
             var      user = db.Users.Find(User.Identity.GetUserId());
             TeamUser tu   = new TeamUser();
             tu.Id     = user.Id;
             tu.TeamId = team.TeamId;
             db.TeamUsers.Add(tu);
             db.Teams.Add(team);
             db.SaveChanges();
             TempData["message"] = "Echipa a fost adaugata!";
             TempData["status"]  = "success";
             return(Redirect("/Projects/New"));
         }
         else
         {
             return(View(team));
         }
     }
     catch (Exception e)
     {
         return(View(team));
     }
 }
Пример #4
0
        public bool AddMember(Guid TeamId, Guid UserId)
        {
            if (HasMember(TeamId, UserId))
            {
                return(false);
            }
            else
            {
                TeamUser tu = new TeamUser()
                {
                    UserId    = UserId,
                    TeamId    = TeamId,
                    CreatedOn = DateTime.Now,
                    IsManager = false
                };
                //如果加进来的是团队管理员角色,则设置一下属性
                var user = _db.User.Find(UserId);
                //如果是团队管理员
                if (user.Role.Contains(RoleConfig.TeamManager))
                {
                    tu.IsManager = true;
                }

                _db.TeamUser.Add(tu);
                _db.SaveChanges();
                return(true);
            }
        }
        public async Task <IActionResult> SignUp([Bind("TeamName, Password, CompetitionID")] Team team)
        {
            if (ModelState.IsValid)
            {
                //BCryptPasswordHash bCryptPasswordHash = new BCryptPasswordHash();
                var salt         = BCryptPasswordHash.GetRandomSalt();
                var hashPassword = BCryptPasswordHash.HashPassword(team.Password, salt);
                team.Password = hashPassword;
                team.Salt     = salt;
                _context.Add(team);
                //get userId
                //var userId = this.User.FindFirst(ClaimTypes.NameIdentifier).Value;
                //Migrating to new way to get user object
                var user = await _userManager.GetUserAsync(HttpContext.User);

                TeamUser teamUser = new TeamUser();
                teamUser.UserId   = user.Id;
                teamUser.UserName = user.UserName;

                teamUser.TeamId = team.TeamID;
                _context.Add(teamUser);
                await _context.SaveChangesAsync();

                return(RedirectToAction("Index", "Competitions"));
            }
            ViewData["CompetitionID"] = team.CompetitionID;
            return(View());
        }
Пример #6
0
        public async Task <ActionResult <TeamUser> > PostTeamUser(TeamUser teamUser)
        {
            _bll.TeamUsers.Add(teamUser);
            await _bll.SaveChangesAsync();

            return(Ok(teamUser));
        }
    public IActionResult AddFirstAndSecond()
    {
        var user = new User
        {
            Name = "Bob"
        };

        _context.Users.Add(user);
        var team = new Team
        {
            Id   = "anotherteamid",
            Name = "B Team"
        };

        _context.Teams.Add(team);
        var teamuser1 = new TeamUser()
        {
            User = user,
            Team = team
        };

        _context.TeamUsers.Add(teamuser1);
        var teamuser2 = new TeamUser()
        {
            User = user,
            Team = team
        };

        _context.TeamUsers.Add(teamuser2);
        _context.SaveChanges();
        return(View());
    }
Пример #8
0
        public async Task <IActionResult> CreateTeam([Bind("Name,Description")] CreateTeamViewModel createTeam, string[] members)
        {
            if (ModelState.IsValid)
            {
                //Many-to-Many relationship
                Team team = new Team
                {
                    Members     = new List <TeamUser>(),
                    Description = createTeam.Description,
                    Name        = createTeam.Name
                };
                _context.Add(team);

                //recent
                await _context.SaveChangesAsync();

                foreach (var member in members)
                {
                    var savedTeam = (from t in _context.Teams where t.Name == team.Name select team).SingleOrDefault();
                    //fails if not found.
                    var user     = (from u in _context.Users where u.Email == member select u).SingleOrDefault();
                    var TeamUser = new TeamUser {
                        TeamId = savedTeam.Id, Team = savedTeam, UserId = user.Id, User = user
                    };
                    team.Members.Append(TeamUser);
                    _context.Add(TeamUser);
                }


                await _context.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
            return(View());
        }
        public async Task <IActionResult> CheckApplication(int TeamId, int UserId, bool Successed)
        {
            Application Application = await db.Applications.Where(t => t.Team.TeamId == TeamId).Where(u => u.User.UserId == UserId).FirstAsync();

            Team Team = await db.Teams.Where(t => t.TeamId == TeamId).FirstAsync();

            User User = await db.Users.Where(u => u.UserId == UserId).FirstAsync();

            Application.Checked   = true;
            Application.Successed = Successed;


            if (Successed)
            {
                TeamUser TU = new TeamUser
                {
                    Team = Team,
                    User = User,
                };

                if (User.Course == 1 && Team.Count1 < Team.MaxCount1)
                {
                    Team.Count1 += 1;
                    await db.TeamUsers.AddAsync(TU);
                }
                else if (User.Course == 2 && Team.Count1 < Team.MaxCount2)
                {
                    Team.Count2 += 1;
                    await db.TeamUsers.AddAsync(TU);
                }
            }
            await db.SaveChangesAsync();

            return(Ok());
        }
Пример #10
0
        /// <summary>
        /// Страница заявок для юзера бригады
        /// </summary>
        /// <returns></returns>
        public ActionResult ShowTeamCases()
        {
            string userToken = "";

            if (Request.Cookies["token"] != null)
            {
                userToken = Request.Cookies["token"].Value.ToString();
            }
            else
            {
                return(RedirectToAction("Login", "Registration"));
            }

            User user = _userRepository.GetUsers().FirstOrDefault(x => x.Token == userToken);

            if (user == null)
            {
                return(RedirectToAction("Login", "Registration"));
            }

            TeamUser teamOfUser = _teamUserRepository.GetTeamByUserId(user.UserId);
            var      cases      = GetCaseViewModel(teamOfUser.TeamId);

            return(View("ShowTeamCases", cases));
        }
Пример #11
0
        public async Task <IActionResult> DeleteUserFromTeam([FromBody] TeamUserModel model)
        {
            if (ModelState.IsValid)
            {
                CoalyticsUser user = await _userManager.FindByNameAsync(model.UserName);

                if (user == null)
                {
                    return(BadRequest("Cannot Find the User"));
                }

                CoalyticsTeam team = _repository.GetTeambyTeamName(model.TeamName);

                if (team == null)
                {
                    return(BadRequest("Cannot Find the Team"));
                }
                else
                {
                    TeamUser teamuser = team.TeamUsers.Where(t => t.UserId == user.Id).FirstOrDefault();
                    if (teamuser == null)
                    {
                        return(BadRequest("User not in the Team"));
                    }
                    else
                    {
                        team.TeamUsers.Remove(teamuser);
                        _repository.Save();
                    }
                }
                return(Ok("User has been removed from Team"));
            }
            return(BadRequest());
        }
Пример #12
0
        public async Task <IActionResult> ExitTeam(string VkId, int TeamId)
        {
            User User = await db.Users.Where(u => u.VkId == int.Parse(VkId)).FirstAsync();

            Team Team = await db.Teams.Where(t => t.TeamId == TeamId).FirstAsync();

            TeamUser TU = await db.TeamUsers.Where(u => u.User == User).FirstAsync();

            db.TeamUsers.Remove(TU);

            List <Application> UserApplication = await db.Applications.Where(t => t.Team.ProjectId == Team.ProjectId).Where(u => u.User == User).ToListAsync();

            db.Applications.RemoveRange(UserApplication);
            await db.SaveChangesAsync();


            int countUsersInTeam = db.TeamUsers.Where(t => t.TeamId == TeamId).Select(u => u.User).Count();

            if (countUsersInTeam == 0)
            {
                Team.TeamLead = null;
            }

            Team.Count1 = db.TeamUsers.Where(t => t.Team == Team).Where(u => u.User.Course == 1).Select(u => u.User).Count();
            Team.Count2 = db.TeamUsers.Where(t => t.Team == Team).Where(u => u.User.Course == 2 || u.User.Course == 3).Select(u => u.User).Count();
            await db.SaveChangesAsync();

            return(Ok());
        }
    public IActionResult AddFirst()
    {
        var user = new User
        {
            Name = "Alice"
        };

        _context.Users.Add(user);
        var team = new Team
        {
            Id   = "uniqueteamid",
            Name = "A Team"
        };

        _context.Teams.Add(team);
        var teamuser1 = new TeamUser()
        {
            User = user,
            Team = team
        };

        _context.TeamUsers.Add(teamuser1);
        _context.SaveChanges();
        return(View());
    }
Пример #14
0
        public async Task <Option <UserModel, Error> > Register(RegisterUserModel model)
        {
            var user = Mapper.Map <User>(model);

            var result = await UserManager.CreateAsync(user, model.Password);


            if (result.Succeeded)
            {
                var company = _companyService.GetCompany(model.Email.Split('@')[1], model.CompanyName);

                if (company == null)
                {
                    company = _companyService.AddUpdateCompany(new Company
                    {
                        CreationTime     = DateTime.Now,
                        CreationUserGuid = new Guid(user.Id),
                        DomainName       = model.Email.Split('@')[1],
                        Name             = model.CompanyName
                    });

                    Team team = await _teamService.Save(new Team
                    {
                        Guid             = Guid.NewGuid(),
                        CreationTime     = DateTime.Now,
                        CreationUserGuid = new Guid(user.Id),
                        CompanyGuid      = company.Guid,
                        OwnerGuid        = new Guid(user.Id),
                        Name             = "Default team"
                    });

                    TeamUser teamUser = await _teamUserService.Save(new TeamUser
                    {
                        Guid             = Guid.NewGuid(),
                        CreationTime     = DateTime.Now,
                        CreationUserGuid = new Guid(user.Id),
                        CompanyGuid      = company.Guid,
                        UserGuid         = new Guid(user.Id),
                        TeamGuid         = team.Guid
                    });
                }

                user.CompanyGuid      = company.Guid;
                user.RegistrationDate = DateTime.Now;


                await UserManager.UpdateAsync(user);
            }


            var creationResult = result
                                 .SomeWhen(
                x => x.Succeeded,
                x => x.Errors.Select(e => e.Description).ToArray());

            return(creationResult.Match(
                       some: _ => Mapper.Map <UserModel>(user).Some <UserModel, Error>(),
                       none: errors => Option.None <UserModel, Error>(new Error(errors))));
        }
Пример #15
0
        public async Task <Team> AddMember(TeamUser teamUser)
        {
            await _context.TeamUsers.AddAsync(teamUser);

            await _context.SaveChangesAsync();

            return(await GetById(teamUser.TeamId));
        }
Пример #16
0
        public async Task <TeamUser> AddUserToTeamAsync(TeamUser teamUser)
        {
            await _context.TeamUsers.AddAsync(teamUser);

            await _context.SaveChangesAsync();

            return(teamUser);
        }
Пример #17
0
        //Remove Team User from Team (deletes User data in TeamUser table)
        public async Task <int> RemoveTeamUser(Guid teamid, Team team, string id, AppUser appUser)
        {
            Guid     guidid   = Guid.Parse(id);
            TeamUser teamUser = _context.TeamUsers.Where(x => x.TeamId == teamid && x.AppUserId == guidid && x.AppUser == appUser && x.Team == team).FirstOrDefault();

            _context.TeamUsers.Remove(teamUser);
            return(await _context.SaveChangesAsync());
        }
Пример #18
0
 public static WTeamUser ConvertTeamUser(TeamUser DbTeamUser)
 {
     return(new WTeamUser
     {
         Id = DbTeamUser.Id,
         TeamGroupId = DbTeamUser.TeamGroupId,
         UserId = DbTeamUser.UserId
     });
 }
        public async Task <IActionResult> Join([Bind("TeamID, Password, CompetitionID")] Team team)
        {
            if (team.TeamID == 0)
            {
                @ViewData["Show"] = true;
                return(RedirectToAction("Join", "Competitions", new { id = team.CompetitionID, check = 3 }));
            }

            var localvarTeam = await _context.Teams
                               .Include(t => t.TeamUsers)
                               .FirstOrDefaultAsync(m => m.TeamID == team.TeamID);

            var competition = await _context.Competitions
                              //    .Include(c => c.Teams)
                              //    .ThenInclude(t => t.TeamUsers)
                              .FirstOrDefaultAsync(m => m.ID == localvarTeam.CompetitionID);

            if (localvarTeam.TeamUsers.Count() >= competition.MaxUsers)
            {
                @ViewData["Show"] = true;
                return(RedirectToAction("Join", "Competitions", new { id = team.CompetitionID, check = 1 }));
                //Change error message
            }
            else
            {
                var ProvidedPasswordhash = BCryptPasswordHash.HashPassword(team.Password, localvarTeam.Salt);

                if (localvarTeam.Password.Equals(ProvidedPasswordhash))
                //if (BCryptPasswordHash.ValidatePassword(ProvidedPasswordhash, (localvarTeam.Password)))
                {
                    //if (ModelState.IsValid)
                    //{
                    //get userId
                    //var userId = this.User.FindFirst(ClaimTypes.NameIdentifier).Value;

                    //Migrate to get user object
                    var user = await _userManager.GetUserAsync(HttpContext.User);

                    TeamUser teamUser = new TeamUser();
                    teamUser.UserId   = user.Id;
                    teamUser.UserName = user.UserName;

                    teamUser.TeamId = team.TeamID;
                    _context.Add(teamUser);
                    await _context.SaveChangesAsync();

                    //}
                    return(RedirectToAction("Index", "Competitions"));
                }
                else
                {
                    @ViewData["Show"] = true;
                    return(RedirectToAction("Join", "Competitions", new { id = team.CompetitionID, check = 2 }));
                }
            }
        }
Пример #20
0
        internal object JoinTeam(int teamid, int userid)
        {
            var TeamUser = new TeamUser {
                UserId = userid, TeamId = teamid
            };

            _context.TeamUsers.Add(TeamUser);
            _context.SaveChanges();
            return(TeamUser);
        }
Пример #21
0
        public async Task RemoveRange(int teamId, IEnumerable <string> userIds)
        {
            foreach (var userId in userIds)
            {
                var model = new TeamUser(teamId, userId);
                _dataContext.Entry(model).State = EntityState.Deleted;
            }

            await _dataContext.SaveChangesAsync();
        }
    public IActionResult AddSecond()
    {
        var teamuser2 = new TeamUser()
        {
            UserName = "******",
            TeamId   = "uniqueteamid"
        };

        _context.TeamUsers.Add(teamuser2);
        _context.SaveChanges();
        return(View());
    }
Пример #23
0
        private void OnClickSubmit(object sender, EventArgs e)
        {
            var result = NoResult;

            Task.Factory.StartNew(() =>
            {
                ToggleLayout();

                while (result == NoResult)
                {
                    if (string.IsNullOrEmpty(_teamName.Text))
                    {
                        result = NoTeamName;
                    }
                    else if (_clubId == 0)
                    {
                        result = NoClub;
                    }

                    var foundTeams = DaoManager.Get().TeamDao.Count("name", _teamName.Text);

                    if (foundTeams > 0)
                    {
                        result = TeamNameAlreadyTaken;
                    }
                    else
                    {
                        var newTeam = new Team
                        {
                            Name   = _teamName.Text,
                            ClubId = _clubId
                        };

                        newTeam = DaoManager.Get().TeamDao.Save(newTeam);

                        var newTeamUser = new TeamUser()
                        {
                            TeamId = newTeam.Id,
                            UserId = _application.CurrentUser.Id
                        };

                        DaoManager.Get().TeamUserDao.Save(newTeamUser);
                        result = NoError;
                    }
                }

                ToggleLayout();
            }).ContinueWith(task =>
            {
                ProcessResult(result);
            }, TaskScheduler.FromCurrentSynchronizationContext());
        }
Пример #24
0
 /// <inheritdoc />
 public async Task Remove(int teamId, string userId)
 {
     try
     {
         var model = new TeamUser(teamId, userId);
         _dataContext.Entry(model).State = EntityState.Deleted;
         await _dataContext.SaveChangesAsync();
     }
     catch (DbUpdateException e)
     {
         throw new HttpResponseException(HttpStatusCode.BadRequest, e.Message);
     }
 }
Пример #25
0
        public async Task <IActionResult> PutTeamUser(Guid id, TeamUser teamUser)
        {
            if (id != teamUser.Id)
            {
                return(BadRequest());
            }

            await _bll.TeamUsers.UpdateAsync(teamUser);

            await _bll.SaveChangesAsync();

            return(NoContent());
        }
Пример #26
0
        public async Task <InvokeResult> AddTeamMemberAsync(string teamId, string userId, EntityHeader org, EntityHeader addedByMemberId)
        {
            var team = await _teamRepo.GetTeamAsync(teamId);

            await AuthorizeAsync(team, AuthorizeResult.AuthorizeActions.Update, addedByMemberId, org);

            var member = await _appUserRepo.FindByIdAsync(userId);

            var teamMember = new TeamUser(team.ToEntityHeader(), member.ToEntityHeader());
            await _teamUserRepo.AddTeamMemberAsync(teamMember);

            return(InvokeResult.Success);
        }
Пример #27
0
        public bool RemoveMember(Guid TeamId, Guid UserId)
        {
            TeamUser tu = _db.TeamUser.Where(x => x.TeamId == TeamId && x.UserId == UserId).FirstOrDefault();

            if (tu != null)
            {
                _db.Remove(tu);
                if (_db.SaveChanges() > 0)
                {
                    return(true);
                }
            }
            return(false);
        }
Пример #28
0
        public async Task <IActionResult> Post([FromBody] TeamUserRequest model)
        {
            TeamUser newRecord = null;

            if (ModelState.IsValid)
            {
                InitUserCredentials();

                // check for user
                var user = await _usersService.Get(model.UserGuid);

                if (user == null || user.CompanyGuid != CompanyGuid)
                {
                    return(BadRequest());
                }

                var team = await _teamService.Get(model.TeamGuid);

                if (team == null || team.CompanyGuid != CompanyGuid)
                {
                    return(BadRequest());
                }



                newRecord = new TeamUser
                {
                    Guid             = Guid.NewGuid(),
                    CompanyGuid      = CompanyGuid,
                    CreationTime     = DateTime.UtcNow,
                    CreationUserGuid = UserGuid,
                    TeamGuid         = team.Guid,
                    UserGuid         = model.UserGuid,
                };

                newRecord = _mapper.Map(model, newRecord);

                try
                {
                    await _teamUserService.Save(newRecord);
                }
                catch (Exception e)
                {
                    Log.Error(e.StackTrace);
                    throw;
                }
            }

            return(CreatedAtAction(nameof(Post), _mapper.Map(newRecord, new TeamUserResponse())));
        }
Пример #29
0
        public async Task <IActionResult> JoinTeam(string VkId, int TeamId)
        {
            User User = await db.Users.Where(u => u.VkId == int.Parse(VkId)).FirstAsync();

            int  countUsersInTeam = db.TeamUsers.Where(t => t.TeamId == TeamId).Select(u => u.User).Count();
            Team Team             = await db.Teams.Where(t => t.TeamId == TeamId).FirstAsync();

            TeamUser TU = new TeamUser
            {
                Team   = Team,
                TeamId = TeamId,
                User   = User,
                UserId = User.UserId
            };

            if (countUsersInTeam == 0)
            {
                if (User.Course == 1 && Team.Count1 < Team.MaxCount1)
                {
                    Team.TeamLead = User;
                    Team.Count1  += 1;
                    await db.TeamUsers.AddAsync(TU);
                }
                else if (User.Course == 2 && Team.Count2 < Team.MaxCount2)
                {
                    Team.TeamLead = User;
                    Team.Count2  += 1;
                    await db.TeamUsers.AddAsync(TU);
                }
                List <Application> Applications = await db.Applications.Where(u => u.User == User).ToListAsync();

                db.Applications.RemoveRange(Applications);
            }
            else
            {
                Application Application = new Application {
                    Team      = Team,
                    User      = User,
                    Checked   = false,
                    Successed = false,
                    Date      = DateTime.Now,
                };
                await db.Applications.AddAsync(Application);
            }

            await db.SaveChangesAsync();

            return(Ok());
        }
        //Delete team from INmemory Db and return teams
        public async Task <bool> UserDeleteAsync(TeamUser user)
        {
            var users = _dbContext.TeamUsers.FirstOrDefault(e => e.LastName == user.LastName);

            if (users != null)
            {
                _dbContext.TeamUsers.Remove(users);
                _dbContext.SaveChanges();
                return(true);
            }
            else
            {
                return(false);
            }
        }
Пример #31
0
 public void ChangeOwner(User newOwner)
 {
     this.Owner = newOwner;
     this.OwnerId = newOwner.Id;
     var teamUser = new TeamUser(this, newOwner);
     teamUser.Status = TeamUserStatus.Approved;
     teamUser.Role = TeamUserRole.Administrator;
     this.Members.Add(teamUser);
 }