Ejemplo n.º 1
0
 public TeamReadDto AddTeam(TeamCreateDto teamCreateDto)
 {
     try
     {
         var newTeam = _unitOfWork.TeamRepository.Add(_mapper.Map <Team>(teamCreateDto));
         _unitOfWork.Commit();
         var user          = _unitOfWork.UserRepository.GetById(teamCreateDto.TeamleaderId);
         var newTeamMember = new TeamMemberCreateDto
         {
             Email     = user.Email,
             Firstname = user.Firstname,
             Lastname  = user.Lastname,
             TeamId    = newTeam.Id
         };
         _unitOfWork.TeamMemberRepository.Add(_mapper.Map <TeamMember>(newTeamMember));
         _unitOfWork.Commit();
         var team = _unitOfWork.TeamRepository.GetTeamIncludingTeamMembersById(newTeam.Id);
         return(_mapper.Map <TeamReadDto>(team));
     }
     catch (DbUpdateException ex) when((ex.InnerException as SqlException)?.Number == 2601)
     {
         _unitOfWork.Rollback();
         throw new Exception($"Team already exists with the name {teamCreateDto.Name}", ex);
     }
 }
Ejemplo n.º 2
0
        public IActionResult CreateTeam([FromBody] TeamCreateDto createTeam)
        {
            if (createTeam == null)
            {
                return(BadRequest());
            }
            if (createTeam.RegionId == null || createTeam.Description == null)
            {
                return(BadRequest());
            }
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (_transActionRepo.TeamExists(createTeam.Name))
            {
                return(BadRequest());
            }

            var newTeam = Mapper.Map <TraTeam>(createTeam);

            _transActionRepo.CreateTeam(newTeam);

            if (!_transActionRepo.Save())
            {
                return(StatusCode(500, "A problem happened while handling your request."));
            }

            var createdTeamToReturn = Mapper.Map <TeamDto>(newTeam);

            return(CreatedAtRoute("GetThatUser", new { id = createdTeamToReturn.UserId }, createdTeamToReturn));
        }
Ejemplo n.º 3
0
        public IActionResult CreateTeam([FromBody] TeamCreateDto createTeam)
        {
            string userGuid = UserHelper.GetUserGuid(_httpContextAccessor);
            var    getUser  = _unitOfWork.User.GetByGuid(userGuid);

            if (getUser.TeamId != null) //User not being able to create team when already in a team
            {
                return(BadRequest(new TransActionResponse("User is already in the team")));
            }
            if (createTeam == null)
            {
                return(BadRequest(new TransActionResponse("No Team Entered")));
            }
            if (!ModelState.IsValid)
            {
                return(BadRequest(new TransActionResponse(ModelState)));
            }

            if (_unitOfWork.Team.GetTeamByName(createTeam.Name))
            {
                return(BadRequest(new TransActionResponse("Team Already Exists")));
            }

            var newTeam = _mapper.Map <TraTeam>(createTeam);

            newTeam.UserId = getUser.UserId;// Sets the user to be the team leader
            _unitOfWork.Team.Create(newTeam);

            if (!_unitOfWork.Save())
            {
                return(StatusCode(500, new TransActionResponse("A problem happened while handling your request.")));
            }

            var createdTeamToReturn = _mapper.Map <TeamDto>(newTeam);

            var user = _unitOfWork.User.GetById(newTeam.UserId);

            user.TeamId = createdTeamToReturn.TeamId;

            user.IsFreeAgent = false;

            var userUpdate = _mapper.Map <UserUpdateDto>(user);

            _unitOfWork.User.Update(user);

            createdTeamToReturn.NumMembers = 1; // intially team will have only one member when created

            if (!_unitOfWork.Save())
            {
                return(StatusCode(500, new TransActionResponse("A problem happened while handling your request.")));
            }

            return(CreatedAtRoute("GetUser", new { id = createdTeamToReturn.UserId }, new TransActionResponse(createdTeamToReturn)));
        }
Ejemplo n.º 4
0
        public ActionResult <TeamReadDto> CreateTeam(TeamCreateDto teamCreateDto)
        {
            var teamModel = _mapper.Map <Team>(teamCreateDto);

            _repository.CreateTeam(teamModel);
            _repository.SaveChanges();

            var teamReadDto = _mapper.Map <TeamReadDto>(teamModel);

            return(CreatedAtRoute(nameof(GetTeamById),
                                  new { ID = teamReadDto.ID }, teamReadDto));
        }
Ejemplo n.º 5
0
        public async Task <IActionResult> Create(TeamCreateDto teamDto)
        {
            if (await _teamService.CheckExists(teamDto.ID))
            {
                return(BadRequest("Team ID already exists!"));
            }
            //var username = User.FindFirst(ClaimTypes.Name).Value;
            //glueIngredientDto.Updated_By = username;
            if (await _teamService.Add(teamDto))
            {
                return(NoContent());
            }

            throw new Exception("Creating the team failed on save");
        }
Ejemplo n.º 6
0
        public async Task <IActionResult> Create([FromBody] TeamCreateDto teamCreateDto)
        {
            var team = _mapper.Map <Team>(teamCreateDto);

            _repository.Create(team);
            var isSuccess = await _repository.SaveChangesAsync();

            if (!isSuccess)
            {
                return(BadRequest());
            }

            var teamViewDto = _mapper.Map <TeamViewDto>(team);

            return(CreatedAtRoute("GetTeam", new { id = teamViewDto.TeamId }, teamViewDto));
        }
Ejemplo n.º 7
0
        public async Task <IActionResult> CreateTeam([FromBody] TeamCreateDto team)
        {
            if (team == null)
            {
                return(BadRequest("TeamDto object is null."));
            }
            else
            {
                var teamEntity = _mapper.Map <Team>(team);
                _repository.Team.CreateTeam(teamEntity);
                await _repository.SaveAsync();

                var teamToReturn = _mapper.Map <TeamDto>(teamEntity);
                return(CreatedAtRoute("GetTeam", new { id = teamToReturn.Id }, teamToReturn));
            }
        }
        public ActionResult <TeamReadDto> AddTeam(TeamCreateDto teamCreateDto)
        {
            if (teamCreateDto == null)
            {
                return(BadRequest());
            }

            try
            {
                var team = _service.AddTeam(teamCreateDto);
                return(CreatedAtAction(nameof(GetTeamById), new { Id = team.Id }, team));
            }
            catch (Exception ex)
            {
                return(BadRequest(ex.Message));
            }
        }
Ejemplo n.º 9
0
        public async Task <IActionResult> Create([FromBody] TeamCreateDto team)
        {
            var country = await _countryRepository.GetByIdAsync(team.CountryId);

            if (country == null)
            {
                return(BadRequest($"Invalid country Id { team.CountryId }"));
            }

            var newTeam = new Team(team.Name, country);

            await _teamRepository.AddAsync(newTeam);

            await _unitOfWork.Commit();

            return(Ok());
        }
Ejemplo n.º 10
0
        private async Task <int> CreateTeam(string name)
        {
            var teamCreateDto = new TeamCreateDto
            {
                TeamName = name
            };
            var client = new HttpClient();
            var url    = $"https://localhost:5001/team/";

            var json = JsonConvert.SerializeObject(teamCreateDto);
            var data = new StringContent(json, Encoding.UTF8, "application/json");

            var responce = await client.PostAsync(url, data);

            var content = await responce.Content.ReadAsStringAsync();

            var teamModel = JsonConvert.DeserializeObject <TeamModel>(content);

            return(teamModel.TeamId);
        }
Ejemplo n.º 11
0
        public async Task <bool> Add(TeamCreateDto model)
        {
            try
            {
                var cat = _mapper.Map <Team>(model);
                _repoTeam.Add(cat);
                await _repoTeam.SaveAll();

                var langs = model.Langs.Select(x => new TeamLang {
                    TeamID = cat.ID, Name = x.Name, LanguageID = x.LanguageID
                }).ToList();
                await _repoTeam.AddTeamLang(langs);

                return(true);
            }
            catch (Exception ex)
            {
                return(false);
            }
        }
Ejemplo n.º 12
0
        public async Task <int> InsertAsync(TeamCreateDto createDto)
        {
            if (createDto == null)
            {
                throw new ArgumentNullException("Entity was null");
            }

            try
            {
                var newTeam = createDto.CreateModelObject();
                context.Teams.Add(newTeam);

                await context.SaveChangesAsync();

                return(newTeam.Id);
            }
            catch (Exception e)
            {
                throw new Exception(e.Message, e);
            }
        }
Ejemplo n.º 13
0
        public IActionResult CreateTeam([FromBody] TeamCreateDto model)
        {
            var result = _eventRepository.GetEventById(model.EventId);

            if (result != null)
            {
                if (result.IsOpen)
                {
                    var password = Helper.GenRandomPassword().ToString();
                    var team     = new Team()
                    {
                        Name     = model.Name,
                        EventId  = model.EventId,
                        Password = password
                    };
                    _teamRepository.Add(team);
                    return(Ok(new TeamPwDto(password, team.Id, result.Id)));
                }
                var ev = _eventRepository.GetEventById(model.EventId);
                _connectionManager.GetHubContext <PostsHub>().Clients.All.sendTeamListSend(ev.Teams);
            }
            return(BadRequest(_apiErrorHandler.GenerateErrorDto(new ErrorList("Event Has already started or doesnt exist"))));
        }
Ejemplo n.º 14
0
        public IActionResult CreateTeam([FromBody] TeamCreateDto createTeam)
        {
            string userGuid = UserHelper.GetUserGuid(_httpContextAccessor);
            var    getUser  = _transActionRepo.GetUsers().FirstOrDefault(c => c.Guid == userGuid);

            //this should take care of user not being able to create team when already in a team
            if (getUser.TeamId != null)
            {
                return(BadRequest());
            }
            if (createTeam == null)
            {
                return(BadRequest());
            }
            if (createTeam.Description == null)
            {
                return(BadRequest());
            }
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (_transActionRepo.TeamExists(createTeam.Name))
            {
                return(BadRequest());
            }

            var newTeam = _mapper.Map <TraTeam>(createTeam);

            newTeam.UserId = getUser.UserId; // SETS THE USER TO BE THE TEAM LEADER
            _transActionRepo.CreateTeam(newTeam);

            if (!_transActionRepo.Save())
            {
                return(StatusCode(500, "A problem happened while handling your request."));
            }

            var createdTeamToReturn = _mapper.Map <TeamDto>(newTeam);

            var user = _unitOfWork.User.GetById(newTeam.UserId);

            user.TeamId = createdTeamToReturn.TeamId;

            //var role = _transActionRepo.GetRoles();
            //var roleId = role.Where(x => x.Name == "Team_Lead").Select(c => c.RoleId).FirstOrDefault();

            //var usersCurrentRole = role.Where(x => x.RoleId == user.RoleId).Select(c => c.Name).FirstOrDefault();

            //if (!usersCurrentRole.Equals("Admin"))
            //{
            //    user.RoleId = roleId;
            //}
            user.IsFreeAgent = false;

            var userUpdate = _mapper.Map <UserUpdateDto>(user);

            _mapper.Map <TraUser>(userUpdate);

            createdTeamToReturn.NumMembers = 1; // intially team will have only one member when created

            if (!_transActionRepo.Save())
            {
                return(StatusCode(500, "A problem happened while handling your request."));
            }

            return(CreatedAtRoute("GetUser", new { id = createdTeamToReturn.UserId }, createdTeamToReturn));
        }
Ejemplo n.º 15
0
 public async Task <int> CreateTeamAsync(TeamCreateDto createDto)
 {
     return(await repository.InsertAsync(createDto));
 }
Ejemplo n.º 16
0
 public Task <int> CreateTeam([FromBody] TeamCreateDto createDto)
 {
     return(teamService.CreateTeamAsync(createDto));
 }
Ejemplo n.º 17
0
 public Task <bool> Update(TeamCreateDto model)
 {
     throw new NotImplementedException();
 }