Exemple #1
0
        public async Task <ApiResponse <AppProductsGetDto> > GetProduct(int id)
        {
            AppProductsGetDto resultDto = new AppProductsGetDto();

            Metadata metadata = new Metadata
            {
                IsValid = true,
                Message = ""
            };

            ApiResponse <AppProductsGetDto> response = new ApiResponse <AppProductsGetDto>(resultDto);

            try
            {
                AppProducts appProductsFind = await GetById(id);

                if (appProductsFind == null)
                {
                    metadata.IsValid = false;
                    metadata.Message = "Codigo de producto no existe, verifique por favor";
                    response.Meta    = metadata;
                    response.Data    = resultDto;
                    return(response);
                }

                resultDto = _mapper.Map <AppProductsGetDto>(appProductsFind);

                AppUnits AppUnitsFind = await _appUnitsService.GetById((int)appProductsFind.AppUnitsId);

                if (AppUnitsFind != null)
                {
                    AppUnitsGetDto appUnitsGetDto = _mapper.Map <AppUnitsGetDto>(AppUnitsFind);
                    resultDto.AppUnitsGetDto = appUnitsGetDto;
                }

                AppUnitsFind = await _appUnitsService.GetById((int)appProductsFind.ProductionUnitId);

                if (AppUnitsFind != null)
                {
                    AppUnitsGetDto appUnitsGetDto = _mapper.Map <AppUnitsGetDto>(AppUnitsFind);
                    resultDto.ProductionUnitGetDto = appUnitsGetDto;
                }


                MtrTipoMoneda MtrTipoMonedaFind = await _mtrTipoMonedaService.GetById((long)appProductsFind.PrymaryMtrMonedaId);

                if (MtrTipoMonedaFind != null)
                {
                    MtrTipoMonedaDto mtrTipoMonedaDto = _mapper.Map <MtrTipoMonedaDto>(MtrTipoMonedaFind);
                    resultDto.PrymaryMtrMonedaGetDto = mtrTipoMonedaDto;
                }

                MtrTipoMonedaFind = await _mtrTipoMonedaService.GetById((long)appProductsFind.SecundaryMtrMonedaId);

                if (MtrTipoMonedaFind != null)
                {
                    MtrTipoMonedaDto mtrTipoMonedaDto = _mapper.Map <MtrTipoMonedaDto>(MtrTipoMonedaFind);
                    resultDto.SecundaryMtrMonedaGetDto = mtrTipoMonedaDto;
                }

                AppSubCategory AppSubCategoryFind = await _appSubCategoryService.GetById((int)appProductsFind.AppSubCategoryId);

                if (AppSubCategoryFind != null)
                {
                    AppSubCategoryGetDto appSubCategoryGetDto = _mapper.Map <AppSubCategoryGetDto>(AppSubCategoryFind);
                    resultDto.AppSubCategoryGetDto = appSubCategoryGetDto;
                }

                if (resultDto.UrlImage == "" || resultDto.UrlImage == null)
                {
                    resultDto.Link = _paginationOptions.UrlGetFiles + "NoImage.png";
                }
                else
                {
                    resultDto.Link = _paginationOptions.UrlGetFiles + resultDto.UrlImage;
                }

                response.Meta = metadata;
                response.Data = resultDto;

                return(response);
            }
            catch (Exception ex)
            {
                metadata.IsValid = false;

                metadata.Message = ex.InnerException.Message;

                response.Meta = metadata;
                response.Data = resultDto;

                return(response);
            }
        }
Exemple #2
0
        public async Task <ApiResponse <List <AppProductsGetDto> > > GetAll(AppProdutsQueryFilter filters)
        {
            filters.PageNumber = filters.PageNumber == 0 ? _paginationOptions.DefaultPageNumber : filters.PageNumber;
            filters.PageSize   = filters.PageSize == 0 ? _paginationOptions.DefaultPageSize : filters.PageSize;

            List <AppProductsGetDto> resultDto = new List <AppProductsGetDto>();

            Metadata metadata = new Metadata
            {
                IsValid = true,
                Message = ""
            };
            ApiResponse <List <AppProductsGetDto> > response = new ApiResponse <List <AppProductsGetDto> >(resultDto);

            try
            {
                var appProducts = await _unitOfWork.AppProductsRepository.GetAllFilter(filters);

                if (appProducts != null)
                {
                    List <AppProductsGetDto> appProductsDto = _mapper.Map <List <AppProductsGetDto> >(appProducts);
                    foreach (var item in appProductsDto)
                    {
                        if (item.UrlImage == "" || item.UrlImage == null)
                        {
                            item.Link = _paginationOptions.UrlGetFiles + "NoImage.png";
                        }
                        else
                        {
                            item.Link = _paginationOptions.UrlGetFiles + item.UrlImage;
                        }

                        AppUnits AppUnitsFind = await _appUnitsService.GetById((int)item.AppUnitsId);

                        if (AppUnitsFind != null)
                        {
                            AppUnitsGetDto appUnitsGetDto = _mapper.Map <AppUnitsGetDto>(AppUnitsFind);
                            item.AppUnitsGetDto = appUnitsGetDto;
                        }

                        AppUnitsFind = await _appUnitsService.GetById((int)item.ProductionUnitId);

                        if (AppUnitsFind != null)
                        {
                            AppUnitsGetDto appUnitsGetDto = _mapper.Map <AppUnitsGetDto>(AppUnitsFind);
                            item.ProductionUnitGetDto = appUnitsGetDto;
                        }


                        MtrTipoMoneda MtrTipoMonedaFind = await _mtrTipoMonedaService.GetById((long)item.PrymaryMtrMonedaId);

                        if (MtrTipoMonedaFind != null)
                        {
                            MtrTipoMonedaDto mtrTipoMonedaDto = _mapper.Map <MtrTipoMonedaDto>(MtrTipoMonedaFind);
                            item.PrymaryMtrMonedaGetDto = mtrTipoMonedaDto;
                        }

                        MtrTipoMonedaFind = await _mtrTipoMonedaService.GetById((long)item.SecundaryMtrMonedaId);

                        if (MtrTipoMonedaFind != null)
                        {
                            MtrTipoMonedaDto mtrTipoMonedaDto = _mapper.Map <MtrTipoMonedaDto>(MtrTipoMonedaFind);
                            item.SecundaryMtrMonedaGetDto = mtrTipoMonedaDto;
                        }

                        AppSubCategory AppSubCategoryFind = await _appSubCategoryService.GetById((int)item.AppSubCategoryId);

                        if (AppSubCategoryFind != null)
                        {
                            AppSubCategoryGetDto appSubCategoryGetDto = _mapper.Map <AppSubCategoryGetDto>(AppSubCategoryFind);
                            item.AppSubCategoryGetDto = appSubCategoryGetDto;
                        }
                    }



                    response.Data = appProductsDto;
                    response.Meta = metadata;
                    return(response);
                }
                else
                {
                    metadata.IsValid = true;
                    metadata.Message = "No Data....";
                    response.Data    = null;
                    response.Meta    = metadata;
                    return(response);
                }
            }
            catch (Exception ex)
            {
                metadata.IsValid = false;
                metadata.Message = ex.InnerException.Message;
                response.Data    = null;
                response.Meta    = metadata;
                return(response);
            }
        }