Beispiel #1
0
        public AssetSubscriptionModel GetSubscriptionForAsset(Guid assetGuid)
        {
            string getAssetSubscriptionQuery = "Select asn.AssetSubscriptionUID as SubscriptionUID,asn.StartDate as SubscriptionStartDate,asn.EndDate as SubscriptionEndDate,asn.fk_CustomerUID as CustomerUID, " +
                                               "(case UTC_TIMESTAMP() between asn.StartDate and asn.EndDate when true then 'Active' else 'InActive' end)  as SubscriptionStatus, st.Name as SubscriptionName " +
                                               "FROM md_subscription_AssetSubscription asn " +
                                               "join md_subscription_ServiceType st on st.ServiceTypeID = asn.fk_ServiceTypeID and st.fk_ServiceTypeFamilyID=1 where asn.fk_AssetUID= " + assetGuid.ToStringAndWrapWithUnhex() + "; ";
            List <OwnerVisibility> assetSubscriptonList = _transaction.Get <OwnerVisibility>(getAssetSubscriptionQuery).ToList();
            AssetSubscriptionModel assetSubscription    = new AssetSubscriptionModel();

            if (assetSubscriptonList.Any() && assetSubscriptonList[0] != null)
            {
                var lstCustomers = GetCustomerByCustomerGuids(assetSubscriptonList.Select(x => x.CustomerUID).Distinct().ToList().ToArray());
                if (lstCustomers.Any())
                {
                    foreach (OwnerVisibility vi in assetSubscriptonList)
                    {
                        var customer = lstCustomers.Where(x => x.CustomerUID == vi.CustomerUID).Select(y => y).ToList().FirstOrDefault();
                        if (customer != null)
                        {
                            vi.CustomerName = customer.CustomerName;
                            vi.CustomerType = customer.CustomerType;
                        }
                    }
                }
                assetSubscription.AssetUID           = assetGuid;
                assetSubscription.SubscriptionStatus = (assetSubscriptonList.Where(s => s.SubscriptionStatus == "Active").ToList().Any()) == true ? "Active" : "InActive";
                assetSubscription.OwnersVisibility   = assetSubscriptonList.ToList();
            }
            return(assetSubscription);
        }
Beispiel #2
0
        public ActionResult GetAssetDetail([FromQuery] Guid?assetUID = null, [FromQuery] Guid?deviceUID = null)
        {
            try
            {
                if (assetUID == null && deviceUID == null)
                {
                    return(BadRequest("AssetUID/DeviceUID has not been provided"));
                }
                try
                {
                    if (assetUID != null && deviceUID != null)
                    {
                        _controllerUtilities.ValidateAssetUIDParameters(new[] { assetUID.ToString(), deviceUID.ToString() });
                    }
                    else if (assetUID != null)
                    {
                        _controllerUtilities.ValidateAssetUIDParameters(new[] { assetUID.ToString() });
                    }
                    else if (deviceUID != null)
                    {
                        _controllerUtilities.ValidateAssetUIDParameters(new[] { deviceUID.ToString() });
                    }
                }
                catch (Exception ex)
                {
                    _logger.LogError("Get Assets parameter validation threw an exception", ex);
                    return(BadRequest(ex.Message));
                }

                if (assetUID != null || deviceUID != null)
                {
                    AssetSubscriptionModel           subscription      = null;
                    List <ClientModel.AssetCustomer> lstAssetCustomers = null;
                    List <AssetDetail> assetDetails = (List <AssetDetail>)_assetRepository.GetAssetDetail(assetUID, deviceUID);
                    if (assetDetails == null)
                    {
                        _logger.LogInformation($"No asset with UID {assetUID} exists");
                        return(StatusCode((int)HttpStatusCode.NoContent, assetUID));
                    }
                    List <AssetDeviceDetail> lstAssetDetails = new List <AssetDeviceDetail>();
                    foreach (AssetDetail assetDetail in assetDetails)
                    {
                        if (assetDetail.AssetUID != null)
                        {
                            subscription = new AssetSubscriptionModel();
                            subscription = GetSubscriptionfromAPI(new Guid(assetDetail.AssetUID));

                            lstAssetCustomers = new List <ClientModel.AssetCustomer>();
                            lstAssetCustomers = GetAssetCustomersfromAPI(new Guid(assetDetail.AssetUID));
                        }

                        AssetInfo assetInfo = null;
                        ClientModel.DeviceModel deviceInfo = null;

                        if (assetDetail != null)
                        {
                            if (assetDetail.AssetUID != null)
                            {
                                assetInfo = new AssetInfo
                                {
                                    AssetName    = assetDetail.AssetName,
                                    AssetType    = assetDetail.AssetTypeName,
                                    AssetUID     = assetDetail.AssetUID != null ? (Guid?)new Guid(assetDetail.AssetUID) : null,
                                    MakeCode     = assetDetail.MakeCode,
                                    Model        = assetDetail.Model,
                                    ModelYear    = assetDetail.ModelYear,
                                    SerialNumber = assetDetail.SerialNumber
                                };
                            }

                            deviceInfo = new ClientModel.DeviceModel
                            {
                                DeviceSerialNumber = assetDetail.DeviceSerialNumber,
                                DeviceState        = ((DeviceStateEnum)Enum.Parse(typeof(DeviceStateEnum), assetDetail.DeviceState)).ToString(),                          //assetDetail.DeviceState,
                                DeviceType         = assetDetail.DeviceType,
                                DeviceUID          = assetDetail.DeviceUID != null ? (Guid?)new Guid(assetDetail.DeviceUID) : null
                            };
                        }
                        AssetDeviceDetail assetDet = new AssetDeviceDetail
                        {
                            AssetInfo    = assetInfo,
                            DeviceInfo   = deviceInfo,
                            Subscription = subscription,
                            AccountInfo  = lstAssetCustomers
                        };
                        lstAssetDetails.Add(assetDet);
                    }
                    return(Ok(lstAssetDetails));
                }
            }
            catch (Exception ex)
            {
                _logger.LogError("GetAssetDetail encountered an error", ex);
                return(StatusCode((int)HttpStatusCode.InternalServerError, ex.Message));
            }
            return(Ok(new List <VSS.MasterData.WebAPI.DbModel.Asset>()));
        }