Exemple #1
0
        // GET: api/AssetWorkDefinition
        public async Task <ActionResult <AssetSettingsListResponse> > Get([FromQuery] AssetSettingsListRequest request)
        {
            if (request == null)
            {
                request = new AssetSettingsListRequest();
            }
            if (request.PageNumber <= 0)
            {
                if (_configurations.ApplicationSettings.DefaultPageNumber.HasValue)
                {
                    request.PageNumber = _configurations.ApplicationSettings.DefaultPageNumber.Value;
                }
            }
            if (request.PageSize <= 0)
            {
                if (_configurations.ApplicationSettings.DefaultPageSize.HasValue)
                {
                    request.PageSize = _configurations.ApplicationSettings.DefaultPageSize.Value;
                }
            }

            request.CustomerUid = base.GetCustomerContext(Request);

            request.UserUid = base.GetUserContext(Request);

            this._loggingService.Debug("Started fetching essential assets for request : " + JsonConvert.SerializeObject(request), MethodInfo.GetCurrentMethod().Name);
            var result = await this._assetSettingsListService.FetchEssentialAssets(request);

            this._loggingService.Debug("End fetching essential assets", MethodInfo.GetCurrentMethod().Name);
            return(base.SendResponse(HttpStatusCode.OK, result));
        }
Exemple #2
0
 private void SetupController(int count, AssetSettingsListRequest request, Guid?customerUID, Guid?userUID)
 {
     _injectConfig.BuildRepositoryStub(count);
     _target = _injectConfig.Resolve <AssetSettingsListController>();
     _target.ControllerContext = GetMockHttpContext();
     if (customerUID != null)
     {
         _target.ControllerContext.HttpContext.Request.Headers.Add(Constants.VISIONLINK_CUSTOMERUID, customerUID.ToString());
     }
     if (userUID != null)
     {
         _target.ControllerContext.HttpContext.Request.Headers.Add(Constants.USERUID_API, userUID.ToString());
     }
     _target.ControllerContext.HttpContext.Request.Body = new MemoryStream(System.Text.Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(request)));
 }
Exemple #3
0
        public async Task <AssetSettingsListResponse> FetchEssentialAssets(AssetSettingsListRequest request)
        {
            try
            {
                var deviceTypeParameterAttributes = await this._parameterAttributeCache.Get(request.DeviceType);

                var validationResponse = await this.Validate <AssetSettingsListRequest>(_assetSettingsListValidators, request);

                var invalidRecords = validationResponse.Where(x => x.IsInvalid);
                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);

                    var assetSettingsListRequestDto = new AssetSettingsListRequestDto
                    {
                        PageSize              = request.PageSize,
                        PageNumber            = request.PageNumber,
                        FilterName            = request.FilterName,
                        FilterValue           = request.FilterValue,
                        DeviceType            = request.DeviceType,
                        SubAccountCustomerUid = request.SubAccountCustomerUid.HasValue ? request.SubAccountCustomerUid.Value.ToString("N") : null,
                        CustomerUid           = request.CustomerUid.HasValue ? request.CustomerUid.Value.ToString("N") : null,
                        UserUid   = request.UserUid.HasValue ? request.UserUid.Value.ToString("N") : null,
                        StatusInd = 1
                    };

                    if (!string.IsNullOrEmpty(request.SortColumn))
                    {
                        assetSettingsListRequestDto.SortDirection = request.SortColumn.StartsWith("-") ? "DESC" : "ASC";
                        request.SortColumn = request.SortColumn.Replace("-", string.Empty);
                        assetSettingsListRequestDto.SortColumn = request.SortColumn;
                    }

                    await this.AssignDefaultValues(deviceTypeParameterAttributes, assetSettingsListRequestDto);

                    this._loggingService.Debug("Started Querying", MethodInfo.GetCurrentMethod().Name);
                    var essentialAssetsData = await this._assetSettingsListRepository.FetchEssentialAssets(assetSettingsListRequestDto);

                    this._loggingService.Debug("Ended Querying", MethodInfo.GetCurrentMethod().Name);

                    await this.AssignTotalSwitchesCount(deviceTypeParameterAttributes, request, essentialAssetsData.Item2);

                    var essentialAssets = this._mapper.Map <List <AssetSettingsDetails> >(essentialAssetsData.Item2);
                    var response        = new AssetSettingsListResponse(essentialAssets, request.PageSize, request.PageNumber, essentialAssetsData.Item1);
                    response.Errors = validationResponse.OfType <ErrorInfo>().ToList();
                    return(await Task.FromResult(response));
                }
            }
            catch (DomainException ex)
            {
                this._loggingService.Error("Error occurred in validation", MethodInfo.GetCurrentMethod().Name, ex);
                throw ex;
            }
        }
Exemple #4
0
        private async Task AssignTotalSwitchesCount(IEnumerable <DeviceTypeParameterAttributeDto> parameterAttributes, AssetSettingsListRequest request, IList <AssetSettingsListDto> assetSettingsListDtos)
        {
            if (parameterAttributes != null && parameterAttributes.Any())
            {
                var totalSwitchesCount = await this.GetTotalSwitchesCount(parameterAttributes, true, request.DeviceType);

                foreach (var assetSettingsListDto in assetSettingsListDtos)
                {
                    assetSettingsListDto.TotalSwitches = totalSwitchesCount;
                }
            }
            await Task.Yield();
        }