示例#1
0
        public HttpResponseMessage GetById(HttpRequestMessage request,
                                           [FromBody] ProductViewModel productViewModel)
        {
            TransactionalInformation transactionalInformation;
            HttpResponseMessage      response;
            var productId  = productViewModel.ID;
            var productDto = _productBusinessService.GetProduct(productId, out transactionalInformation);

            if (transactionalInformation.ReturnStatus == false)
            {
                productViewModel.ReturnStatus     = false;
                productViewModel.ReturnMessage    = transactionalInformation.ReturnMessage;
                productViewModel.ValidationErrors = transactionalInformation.ValidationErrors;

                var responseError = request.CreateResponse(HttpStatusCode.BadRequest, productViewModel);
                return(responseError);
            }
            else
            {
                productViewModel.CopyFromProductDTO(productDto);

                productViewModel.ReturnStatus  = true;
                productViewModel.ReturnMessage = transactionalInformation.ReturnMessage;
                response = request.CreateResponse(HttpStatusCode.OK, productViewModel);
            }

            return(response);
        }
示例#2
0
        /// <summary>
        /// The GetProductDetailById
        /// </summary>
        /// <param name="_productBusinessService">The _productBusinessService<see cref="IProductBusinessService"/></param>
        /// <param name="id">The id<see cref="int"/></param>
        /// <returns>The <see cref="ProductViewModel"/></returns>
        public static ProductViewModel GetProductDetailById(IProductBusinessService _productBusinessService, int id)
        {
            TransactionalInformation transactionalInformation;
            ProductViewModel         productViewModel = new ProductViewModel();
            ProductDTO        productDto;
            List <ProductDTO> productRelatedDto = new List <ProductDTO>();

            _productBusinessService.GetProductDetailsAndProductsRelate(id,
                                                                       out productDto, out productRelatedDto, out transactionalInformation);

            if (transactionalInformation.ReturnStatus == false)
            {
                productViewModel.ReturnStatus     = false;
                productViewModel.ReturnMessage    = transactionalInformation.ReturnMessage;
                productViewModel.ValidationErrors = transactionalInformation.ValidationErrors;
            }
            else
            {
                productViewModel.CopyFromProductDTO(productDto);
                productViewModel.ProductDTOs = productRelatedDto;

                productViewModel.ReturnStatus  = true;
                productViewModel.ReturnMessage = transactionalInformation.ReturnMessage;
            }

            return(productViewModel);
        }