public async Task <IActionResult> Put(string employerAccountId, [FromBody] List <Favourite> favourites)
        {
            try
            {
                if (!_paramValidator.IsValidEmployerAccountId(employerAccountId))
                {
                    throw new ArgumentException("Employer account id is invalid.");
                }

                favourites.ForEach(ValidateApprenticeship);

                var response = await _mediator.Send(new SaveApprenticeshipFavouriteCommand
                {
                    EmployerAccountId = employerAccountId,
                    Favourites        = MapToWriteModel(favourites)
                });

                if (response.CommandResult == Domain.WriteModel.DomainUpdateStatus.Created)
                {
                    return(CreatedAtAction("Get", new { employerAccountId }, string.Empty));
                }

                return(NoContent());
            }
            catch (ArgumentException ex)
            {
                return(BadRequest(ex.Message));
            }
            catch (Exception ex)
            {
                _logger.LogError(ex, "Error in get apprenticeship favourites");
                return(StatusCode(500, ServerErrorMessage));
            }
        }
コード例 #2
0
        public async Task <IActionResult> DeletePost(string employerAccountId, string apprenticeshipId, bool confirmDelete)
        {
            if (!_paramValidator.IsValidEmployerAccountId(employerAccountId) ||
                !_paramValidator.IsValidApprenticeshipId(apprenticeshipId))
            {
                _logger.LogDebug($"Invalid parameters in the following: {nameof(employerAccountId)}({employerAccountId}), {nameof(apprenticeshipId)}({apprenticeshipId})");
                return(BadRequest());
            }

            if (confirmDelete)
            {
                await _mediator.Send(new DeleteApprenticeshipFavouriteCommand()
                {
                    ApprenticeshipId = apprenticeshipId, EmployerAccountId = employerAccountId
                });
            }

            return(RedirectToAction("Index", new { employerAccountId }));
        }