Beispiel #1
0
        public EditProductViewModel Create(int id)
        {
            EditProductViewModel viewModel = new EditProductViewModel();

            viewModel.UpdateProductModel = new UpdateProductModel();

            var productDetails = getProductDetailsQuery.Execute(id);

            viewModel.ProductDetailsModel = productDetails;

            viewModel.UpdateProductModel.ProductID          = productDetails.ProductID;
            viewModel.UpdateProductModel.ProductName        = productDetails.ProductName;
            viewModel.UpdateProductModel.ProductTypeCode    = productDetails.ProductTypeCode;
            viewModel.UpdateProductModel.OtherDetails       = productDetails.OtherDetails;
            viewModel.UpdateProductModel.ProductDescription = productDetails.ProductDescription;
            viewModel.UpdateProductModel.ReorderLevel       = productDetails.ReorderLevel;
            viewModel.UpdateProductModel.ReorderQuantity    = productDetails.ReorderQuantity;
            viewModel.UpdateProductModel.UnitPrice          = productDetails.UnitPrice;

            var productTypesList = getProductTypesListQuery.Execute();

            viewModel.productTypesList = productTypesList.Select(p => new SelectListItem()
            {
                Value = p.ProductTypeCode.ToString(),
                Text  = p.ProductTypeDescription.ToString()
            })
                                         .ToList();


            return(viewModel);
        }
 public IActionResult GetProductById(int id)
 {
     try
     {
         return(Ok(_detailsQuery.Execute(id)));
     }
     catch (Exception e)
     {
         return(StatusCode(StatusCodes.Status500InternalServerError, e.Message));
     }
 }