public async Task <ActionResult> DeleteProfileAsync( [BindRequired, FromQuery] string profileId, [BindRequired] Agent agent, [BindRequired, FromHeader(Name = "Content-Type")] string contentType, CancellationToken cancelToken = default) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var profile = await _mediator.Send(GetAgentProfileQuery.Create(agent, profileId), cancelToken); if (Request.TryConcurrencyCheck(profile?.Document.Checksum, profile?.Document.LastModified, out int statusCode)) { return(StatusCode(statusCode)); } if (profile == null) { return(NotFound()); } await _mediator.Send(DeleteAgentProfileCommand.Create(profileId, agent), cancelToken); return(NoContent()); }
public async Task DeleteAgentProfile(Agent agent, string profileId, CancellationToken cancellationToken = default) { var agentEntity = await mediator.Send(GetAgentQuery.Create(agent), cancellationToken); if (agentEntity == null) { return; } await mediator.Send(DeleteAgentProfileCommand.Create(profileId, agentEntity.AgentId), cancellationToken); }
public async Task <Unit> Handle(DeleteAgentProfileCommand request, CancellationToken cancellationToken) { var agentEntity = _mapper.Map <AgentEntity>(request.Agent); AgentProfileEntity profile = await GetAgentProfile(agentEntity, request.ProfileId, cancellationToken); if (profile != null) { _context.AgentProfiles.Remove(profile); } return(await Unit.Task); }