Пример #1
0
        public async Task <ActionResult> Post([FromBody] CreateServiceRequest req)
        {
            string serviceRequestAggregateId = "";
            ServiceRequestAggregate serviceRequestAggregate;

            try
            {
                // 1. Try to create the aggregate
                string user = ""; // Pull this out of auth or something
                string guid = Guid.NewGuid().ToString();
                serviceRequestAggregate = new ServiceRequestAggregate(
                    guid,
                    req.buildingCode,
                    req.description,
                    (int)ServiceRequestStatus.Created,
                    req.createdBy,
                    DateTime.Now,
                    user,
                    DateTime.Now
                    );

                // 2. Persist aggregate
                serviceRequestAggregateId = await _repo.CreateAsync(serviceRequestAggregate);
            }
            catch (ServiceRequestDomainException ex)
            {
                return(BadRequest(ex.Message));
            }

            try
            {
                // 3. Sideaffects
                SendEmail(serviceRequestAggregate);
            }
            catch (Exception ex)
            {
                // log
            }
            return(Created($"api/servicerequest/{serviceRequestAggregateId}", serviceRequestAggregate));
        }