Пример #1
0
        public async Task <AgentProfileDocument> Handle(GetAgentProfileQuery request, CancellationToken cancellationToken)
        {
            var agentEntity = _mapper.Map <AgentEntity>(request.Agent);
            var profile     = await GetAgentProfile(agentEntity, request.ProfileId, cancellationToken);

            return(_mapper.Map <AgentProfileDocument>(profile));
        }
Пример #2
0
        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());
        }
Пример #3
0
        public async Task <ActionResult> DeleteProfileAsync(string profileId, [FromQuery(Name = "agent")] string strAgent)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            string contentType = Request.ContentType;
            Agent  agent       = new Agent(strAgent);

            var profile = await _mediator.Send(GetAgentProfileQuery.Create(agent, profileId));

            if (profile == null)
            {
                return(NotFound());
            }

            // TODO: Concurrency

            await _mediator.Send(new DeleteAgentProfileCommand()
            {
                ProfileId = profileId,
                Agent     = agent
            });

            return(NoContent());
        }
Пример #4
0
        public async Task <AgentProfileDocument> Handle(MergeAgentProfileCommand request, CancellationToken cancellationToken)
        {
            var profile = await Handle(GetAgentProfileQuery.Create(request.Agent, request.ProfileId), cancellationToken);

            if (profile == null)
            {
                return(await Handle(
                           CreateAgentProfileCommand.Create(request.Agent, request.ProfileId, request.Content, request.ContentType),
                           cancellationToken));
            }

            return(await Handle(UpdateAgentProfileCommand.Create(request.Agent, request.ProfileId, request.Content, request.ContentType), cancellationToken));
        }
Пример #5
0
        public async Task <AgentProfileEntity> Handle(UpsertAgentProfileCommand request, CancellationToken cancellationToken)
        {
            var profile = await _mediator.Send(GetAgentProfileQuery.Create(request.AgentId, request.ProfileId), cancellationToken);

            if (profile == null)
            {
                return(await _mediator.Send(
                           CreateAgentProfileCommand.Create(request.AgentId, request.ProfileId, request.Content, request.ContentType),
                           cancellationToken));
            }

            return(await _mediator.Send(UpdateAgentProfileCommand.Create(request.AgentId, request.ProfileId, request.Content, request.ContentType), cancellationToken));
        }
Пример #6
0
        public async Task <IDocument> GetAgentProfile(Agent agent, string profileId, CancellationToken cancellationToken = default)
        {
            var agentEntity = await mediator.Send(GetAgentQuery.Create(agent), cancellationToken);

            if (agentEntity == null)
            {
                return(null);
            }

            var profile = await mediator.Send(GetAgentProfileQuery.Create(agentEntity.AgentId, profileId));

            return(mapper.Map <IDocument>(profile));
        }
Пример #7
0
        public async Task <ActionResult> SaveAgentProfileAsync(
            [BindRequired, FromQuery] string profileId,
            [BindRequired, FromQuery] Agent agent,
            [BindRequired, FromHeader(Name = "Content-Type")] string contentType,
            [BindRequired, FromBody] byte[] content,
            CancellationToken cancellationToken = default)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var profile = await _mediator.Send(GetAgentProfileQuery.Create(agent, profileId), cancellationToken);

            if (Request.TryConcurrencyCheck(profile?.Document.Checksum, profile?.Document.LastModified, out int statusCode))
            {
                return(StatusCode(statusCode));
            }

            if (profile == null)
            {
                profile = await _mediator.Send(
                    CreateAgentProfileCommand.Create(agent, profileId, content, contentType),
                    cancellationToken);
            }
            else
            {
                profile = await _mediator.Send(
                    UpdateAgentProfileCommand.Create(agent, profileId, content, contentType),
                    cancellationToken);
            }

            Response.Headers.Add(HeaderNames.ETag, $"\"{profile.Document.Checksum}\"");
            Response.Headers.Add(HeaderNames.LastModified, profile.Document.LastModified?.ToString("o"));

            return(NoContent());
        }