Esempio n. 1
0
        public async Task <IActionResult> PutTeam(int id, UpdateTeamViewModel updateTeamViewModel)
        {
            if (id != updateTeamViewModel.Updated.Id)
            {
                return(BadRequest());
            }

            try
            {
                await _teamService.EditTeam(_mapper.Map <TeamDTO>(updateTeamViewModel));
            }
            catch (TeamDeletedException)
            {
                return(Problem(detail: "The team has been deleted by other user"));
            }
            catch (TeamModifiedException)
            {
                return(Problem(detail: "The team has been modified by other user"));
            }
            catch (TeamNotExistedException)
            {
                return(Problem(detail: "The team does not exist"));
            }
            catch (TeamNameAlreadyExistsException)
            {
                ModelState.AddModelError("Name", "A team already exists with this name");
                return(ValidationProblem(statusCode: (int)HttpStatusCode.Conflict, modelStateDictionary: ModelState));
            }

            return(NoContent());
        }
Esempio n. 2
0
        public async Task <IActionResult> PutAsync([FromBody] UpdateTeamViewModel team)
        {
            if (ModelState.IsValid)
            {
                var newTeamValue = Mapper.Map <TeamDTO>(team);
                if (await _fmService.UpdateTeamValueAsync(newTeamValue))
                {
                    return(Ok(Mapper.Map <UpdateTeamViewModel>(newTeamValue)));
                }
            }

            return(BadRequest("Failed to update team values"));
        }