Beispiel #1
0
        public async Task <ActionResult <DeviceTypeListResponse> > FetchDeviceTypes(AssetDeviceTypeRequest request, [FromQuery] string subAccountCustomerUid = null, [FromQuery] bool isSwitch = false)
        {
            Guid parsedSubAccountCustomerUid;

            request = await base.ReadRequestContentAsync(request);

            if (request == null)
            {
                request = new AssetDeviceTypeRequest();
            }
            request.CustomerUid     = base.GetCustomerContext(Request);
            request.UserUid         = base.GetUserContext(Request);
            request.IsSwitchRequest = isSwitch;

            if (!string.IsNullOrEmpty(subAccountCustomerUid) && Guid.TryParse(subAccountCustomerUid, out parsedSubAccountCustomerUid))
            {
                request.SubAccountCustomerUid = parsedSubAccountCustomerUid.ToString("N");
            }
            if (request.AssetUIDs != null && request.AssetUIDs.Count > 0)
            {
                this._loggingService.Info("Asset UIDs Count : " + request.AssetUIDs.Count, MethodInfo.GetCurrentMethod().Name);
            }
            this._loggingService.Info("Fetching Device Types for the given request : " + JsonConvert.SerializeObject(request), MethodInfo.GetCurrentMethod().Name);
            var result = await this._assetSettingsListService.FetchDeviceTypes(request);

            this._loggingService.Debug("Fetching Device Types response : " + JsonConvert.SerializeObject(result), MethodInfo.GetCurrentMethod().Name);
            return(base.SendResponse(HttpStatusCode.OK, new DeviceTypeListResponse(result)));
        }
Beispiel #2
0
        public async Task <IList <DeviceType> > FetchDeviceTypes(AssetDeviceTypeRequest request)
        {
            try
            {
                var validationResponse = await this.Validate <IServiceRequest>(_serviceRequestParametersValidators, request);

                var invalidRecords             = validationResponse.Where(x => x.IsInvalid);
                IList <DeviceType> deviceTypes = new List <DeviceType>();
                if (invalidRecords.Any())
                {
                    this._loggingService.Info("Ignoring request since following records are invalid : " + JsonConvert.SerializeObject(invalidRecords), MethodInfo.GetCurrentMethod().Name);
                    throw new DomainException {
                              Errors = validationResponse
                    };
                }
                else
                {
                    this._loggingService.Debug("Building AssetTargetWorkDefinitionRequestDto", MethodInfo.GetCurrentMethod().Name);

                    request.StatusInd    = 1;
                    request.UserGuid     = request.UserUid.Value.ToString("N");
                    request.CustomerGuid = request.CustomerUid.Value.ToString("N");

                    var deviceTypeDtos = await this._assetSettingsListRepository.FetchDeviceTypesByAssetUID(request);

                    if (deviceTypeDtos != null && deviceTypeDtos.Item1 > 0)
                    {
                        deviceTypes = deviceTypeDtos.Item2.Select(x => new DeviceType
                        {
                            Id         = x.DeviceType,
                            Name       = x.DeviceType,
                            AssetCount = x.AssetCount
                        }).ToList();
                    }
                }
                return(deviceTypes);
            }
            catch (DomainException ex)
            {
                this._loggingService.Error("Error occurred in validation", MethodInfo.GetCurrentMethod().Name, ex);
                throw ex;
            }
        }
Beispiel #3
0
        public void FetchDeviceTypes_Test(AssetDeviceTypeRequest request, int errorCode, string errorMessage)
        {
            try
            {
                var response = _assetSettingsListService.FetchDeviceTypes(request).Result;

                Assert.NotNull(response);
                Assert.Equal(response.Count, 3);
            }
            catch (AggregateException aggregateEx)
            {
                Assert.NotNull(aggregateEx.InnerException);
                var domainEx = (DomainException)aggregateEx.InnerException;
                Assert.NotNull(domainEx);
                Assert.NotNull(domainEx.Errors);
                Assert.True(domainEx.Errors.Any());
                Assert.Equal(domainEx.Errors.First().ErrorCode, errorCode);
                Assert.Equal(domainEx.Errors.First().Message, errorMessage);
            }
        }
Beispiel #4
0
        public async Task <Tuple <int, IEnumerable <DeviceTypeDto> > > FetchDeviceTypesByAssetUID(AssetDeviceTypeRequest request)
        {
            try
            {
                string subAccountCustomerCondition = string.Empty;
                int    foundRows = 0;
                this._loggingService.Debug("Started executing query", string.Format(LogMethodFormat, "FetchDeviceTypes"));

                if (!string.IsNullOrEmpty(request.SubAccountCustomerUid))
                {
                    subAccountCustomerCondition = subAccountCustomerCondition = " AND " + string.Format(" ca.fk_AssetUID IN ({0}) ", Queries.FetchAssetUIDsForSubAccountCustomerUID);
                }

                var resultSet = request.IsSwitchRequest ? request.AssetUIDs != null && request.AssetUIDs.Count() > 0 && !request.AllAssets
                                    ? await this._transactions.GetMultipleResultSetAsync <DeviceTypeDto, long>(string.Format(Queries.FetchDeviceTypesForCustomerAndUserAndSwitchesGroup, subAccountCustomerCondition, string.Format(Queries.OrderByClause, "TypeName", "ASC"), Queries.SelectFoundRows, string.Format("And {0}", string.Format(Constants.AssetSettingsFilterConfig[AssetSettingsFilters.AssetUID], string.Join(",", request.AssetUIDs.Select(assetUID => string.Format("UNHEX('{0}')", assetUID.ToString("N"))))))), request)
                                    : await this._transactions.GetMultipleResultSetAsync <DeviceTypeDto, long>(string.Format(Queries.FetchDeviceTypesForCustomerAndUserAndSwitchesGroup, subAccountCustomerCondition, string.Format(Queries.OrderByClause, "TypeName", "ASC"), Queries.SelectFoundRows, string.Empty), request) :
                                request.AssetUIDs != null && request.AssetUIDs.Count() > 0 && !request.AllAssets
                                    ? await this._transactions.GetMultipleResultSetAsync <DeviceTypeDto, long>(string.Format(Queries.FetchDeviceTypesForCustomerAndUser, subAccountCustomerCondition, string.Format(Queries.OrderByClause, "TypeName", "ASC"), Queries.SelectFoundRows, string.Format("And {0}", string.Format(Constants.AssetSettingsFilterConfig[AssetSettingsFilters.AssetUID], string.Join(",", request.AssetUIDs.Select(assetUID => string.Format("UNHEX('{0}')", assetUID.ToString("N"))))))), request)
                                    : await this._transactions.GetMultipleResultSetAsync <DeviceTypeDto, long>(string.Format(Queries.FetchDeviceTypesForCustomerAndUser, subAccountCustomerCondition, string.Format(Queries.OrderByClause, "TypeName", "ASC"), Queries.SelectFoundRows, string.Empty), request);

                this._loggingService.Debug("Ended executing query", string.Format(LogMethodFormat, "FetchEssentialAssets"));

                var deviceLists     = resultSet.Item1 as IList <DeviceTypeDto>;
                var deviceFoundRows = resultSet.Item2 as IList <long>;
                if (deviceFoundRows != null && deviceFoundRows.Any())
                {
                    foundRows = Convert.ToInt32((deviceFoundRows).FirstOrDefault());
                }
                this._loggingService.Debug("Ended executing query", string.Format(LogMethodFormat, "FetchDeviceTypes"));
                return(new Tuple <int, IEnumerable <DeviceTypeDto> >(foundRows, deviceLists));
            }
            catch (Exception ex)
            {
                throw;
            }
        }