public async Task <CompleteServiceRequestCommand> HandleAsync(CompleteServiceRequestCommand command)
        {
            var request = await _repository.GetByIdAsync(command.RequestId);

            request.Completed();
            await _repository.UpdateAsync(request);

            return(command);
        }
Esempio n. 2
0
        public async Task <ActionResult> Put(string id, [FromBody] UpdateServiceRequest req)
        {
            var serviceRequest = await _query.GetAsync(id);

            if (serviceRequest != null)
            {
                try
                {
                    // 1. try to rebuild aggregate
                    ServiceRequestAggregate serviceRequestAggregate = new ServiceRequestAggregate(
                        serviceRequest.Id,
                        serviceRequest.BuildingCode,
                        serviceRequest.Description,
                        serviceRequest.Status,
                        serviceRequest.CreatedBy,
                        serviceRequest.CreatedDate,
                        serviceRequest.LastModifiedBy,
                        serviceRequest.LastUpdatedBy
                        );

                    // 2. try to update status
                    //  I assumed this was the main thing to update?
                    //  if more needs to be updated the aggregate can be extended with methods to do so
                    serviceRequestAggregate.UpdateStatus(req.status);

                    // 2. persist new aggregate
                    await _repo.UpdateAsync(serviceRequestAggregate);

                    return(Ok(serviceRequestAggregate));
                } catch (ServiceRequestDomainException ex)
                {
                    return(BadRequest(ex.Message));
                }
            }
            else
            {
                return(NotFound("Resource Not Found"));
            }
        }