Esempio n. 1
0
        public async Task <ActionResult> Delete(string id)
        {
            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. Archive this aggregate
                    await _repo.ArchiveAsync(serviceRequestAggregate);

                    return(Created($"api/servicerequest/{serviceRequestAggregate.Id}", serviceRequestAggregate));
                }
                catch (ServiceRequestDomainException ex)
                {
                    return(BadRequest("Invalid request"));
                }
            }
            else
            {
                return(NotFound("Resource Not Found"));
            }
        }