public HttpResponseMessage UpdateServiceResults([FromBody] ServiceProvisioningResult serviceProvisioningResult) { try { Setup(); if (serviceProvisioningResult == null) { throw new Exception("Must provide serviceProvisioningResult info."); } _logger.WriteLogEntry(_tenantId.ToString(), new List <object> { serviceProvisioningResult }, string.Format(MethodBase.GetCurrentMethod().Name + " in " + _name), LogLevelType.Info); var orderStatus = _iOrderService.UpdateServiceResult(serviceProvisioningResult, _user); return(this.Request.CreateResponse(HttpStatusCode.OK, orderStatus)); } catch (Exception ex) { _logger.WriteLogEntry(_tenantId.ToString(), new List <object> { serviceProvisioningResult, ex.RetrieveEntityExceptionDataAsObjectList() }, string.Format(MethodBase.GetCurrentMethod().Name + " in " + _name), LogLevelType.Error, ex.GetInnerMostException()); throw ex.AddEntityValidationInfo(); } }
public ServiceStatus UpdateServiceResult(ServiceProvisioningResult serviceProvisioningResult, string updatingUserId) { if (serviceProvisioningResult.Id < 1) { throw new Exception("ServiceId is a mandatory field and you are missing this."); } UpdateServiceStatus(serviceProvisioningResult.Id, serviceProvisioningResult.StatusType, 0, serviceProvisioningResult.ErrorMessage, serviceProvisioningResult.Log, serviceProvisioningResult.StartDate, serviceProvisioningResult.CompletionDate, updatingUserId); var statusTypes = new[] { StatusType.Pending, StatusType.Processing }; //Get current service so we have the orderId. var service = RetrieveServiceById(serviceProvisioningResult.Id); //Now that all status have been updated on services re-query db and see if all services have now been provisioned. var order = RetrieveOrderById(service.OrderId); string serviceErrors = order.Services.Where(p => p.StatusType == StatusType.Error).Aggregate("", (current, error) => current + (error.ResultMessage + Environment.NewLine)); string serviceLogs = order.Services.Aggregate("", (current, error) => current + (error.Log + Environment.NewLine)); if (!order.Services.Any(p => statusTypes.Contains(p.StatusType))) { //must fetch each service and make none errored. var statusType = StatusType.Success; if (order.Services.Any(p => p.StatusType == StatusType.Error)) { statusType = StatusType.Error; } UpdateOrderStatus( order.Id, statusType, 0, serviceErrors, serviceLogs, null, null, updatingUserId); } else { //If all services are not complete then set back to pending to get picked up again. UpdateOrderStatus( order.Id, StatusType.Pending, 0, "", "", null, null, updatingUserId); } //Now get the orderstatus return(RetrieveServiceStatusById(serviceProvisioningResult.Id)); }