public HttpResponseMessage UpdateItemResults([FromBody] ItemProvisioningResult itemProvisioningResult) { try { Setup(); if (itemProvisioningResult == null) { throw new Exception("Must provide itemProvisioningResult info."); } _logger.WriteLogEntry(_tenantId.ToString(), new List <object> { itemProvisioningResult }, string.Format(MethodBase.GetCurrentMethod().Name + " in " + _name), LogLevelType.Info); var orderStatus = _iOrderService.UpdateItemResult(itemProvisioningResult, _user); return(this.Request.CreateResponse(HttpStatusCode.OK, orderStatus)); } catch (Exception ex) { _logger.WriteLogEntry(_tenantId.ToString(), new List <object> { itemProvisioningResult, ex.RetrieveEntityExceptionDataAsObjectList() }, string.Format(MethodBase.GetCurrentMethod().Name + " in " + _name), LogLevelType.Error, ex.GetInnerMostException()); throw ex.AddEntityValidationInfo(); } }
public ItemStatus UpdateItemResult(ItemProvisioningResult itemProvisioningResult, string updatingUserId) { if (itemProvisioningResult.Id < 1) { throw new Exception("ItemId is a mandatory field and you are missing this."); } int count = 1; foreach (var equipment in itemProvisioningResult.EquipmentResults) { if (equipment.Id < 1) { throw new Exception("EquipmentId is a mandatory field and you are missing this."); } UpdateEquipmentStatus(itemProvisioningResult.Id, equipment.Id, count, equipment.StatusType, equipment.ErrorMessage, equipment.Log, equipment.Name, equipment.StartDate, equipment.CompletionDate, updatingUserId); count++; } //Set item status to results. UpdateItemStatus(itemProvisioningResult.Id, itemProvisioningResult.StatusType, 0, itemProvisioningResult.ErrorMessage, itemProvisioningResult.Log, itemProvisioningResult.StartDate, itemProvisioningResult.CompletionDate, updatingUserId); //Get current service so we have the orderId. var domainItem = RetrieveItemById(itemProvisioningResult.Id); int serviceId = 0; if (domainItem is PhoneItem) { var phoneItem = domainItem as PhoneItem; serviceId = phoneItem.ServiceId; } if (domainItem is VideoItem) { var videoItem = domainItem as VideoItem; serviceId = videoItem.ServiceId; } if (domainItem is InternetItem) { var internetItem = domainItem as InternetItem; serviceId = internetItem.ServiceId; } bool phoneItemsPending = false; bool videoItemsPending = false; bool internetItemsPending = false; bool itemError = false; string phoneItemErrors = string.Empty; string videoItemsErrors = string.Empty; string internetItemsErrors = string.Empty; string phoneItemLogs = string.Empty; string videoItemsLogs = string.Empty; string internetItemsLogs = string.Empty; var statusTypes = new[] { StatusType.Pending, StatusType.Processing }; //Get current service so we have the orderId. var service = RetrieveServiceById(serviceId); foreach (var location in service.Locations) { itemError = location.PhoneItems.Any(p => p.StatusType == StatusType.Error) || location.VideoItems.Any(p => p.StatusType == StatusType.Error) || location.InternetItems.Any(p => p.StatusType == StatusType.Error); phoneItemErrors = location.PhoneItems.Where(p => p.StatusType == StatusType.Error).Aggregate("", (current, error) => current + (error.ResultMessage + Environment.NewLine)); videoItemsErrors = location.VideoItems.Where(p => p.StatusType == StatusType.Error).Aggregate("", (current, error) => current + (error.ResultMessage + Environment.NewLine)); internetItemsErrors = location.InternetItems.Where(p => p.StatusType == StatusType.Error).Aggregate("", (current, error) => current + (error.ResultMessage + Environment.NewLine)); phoneItemLogs = location.PhoneItems.Aggregate("", (current, error) => current + (error.Log + Environment.NewLine)); videoItemsLogs = location.VideoItems.Aggregate("", (current, error) => current + (error.Log + Environment.NewLine)); internetItemsLogs = location.InternetItems.Aggregate("", (current, error) => current + (error.Log + Environment.NewLine)); phoneItemsPending = location.PhoneItems.Any(p => statusTypes.Contains(p.StatusType)); videoItemsPending = location.VideoItems.Any(p => statusTypes.Contains(p.StatusType)); internetItemsPending = location.InternetItems.Any(p => statusTypes.Contains(p.StatusType)); } if (!(phoneItemsPending || videoItemsPending || internetItemsPending)) { //must fetch each service and make sure none errored. var statusType = StatusType.Success; if (itemError) { statusType = StatusType.Error; } UpdateServiceStatus( service.Id, statusType, 0, phoneItemErrors + videoItemsErrors + internetItemsErrors, phoneItemLogs + videoItemsLogs + internetItemsLogs, null, null, updatingUserId); } //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(RetrieveItemStatusById(itemProvisioningResult.Id)); }