Exemple #1
0
        public async Task <ApiResponse> CreateProduct(ProductBusinessModel product)
        {
            //Check if model is not null
            if (product == null)
            {
                return(new ApiResponse()
                {
                    StatusCode = StatusCodes.Status400BadRequest,
                    Result = false,
                    IsSuccess = false,
                    Message = "Empty Object"
                });
            }
            //Construct Data Model
            SupplierProduct supplierProduct = await ConstructProduct(product);

            //Create Product
            var result = await _supplierProductService.CreateAsync(supplierProduct);

            //Get Product
            var response = await _vwAllProductService.GetAsync(pr => pr.ID == supplierProduct.ProductID);

            //Construct Product Supplier
            return(new ApiResponse()
            {
                StatusCode = result?StatusCodes.Status200OK : StatusCodes.Status400BadRequest,
                Result = response,
                IsSuccess = result,
                Message = result? "Successfully Created Product!": "Unable to create product, Check your model and try again!"
            });
        }
Exemple #2
0
        private async Task <SupplierProduct> ConstructProduct(ProductBusinessModel product)
        {
            //Construct Product Data Model
            var productDto = new Product();

            productDto.Name             = product.BrandName;
            productDto.BrandName        = product.BrandName;
            productDto.GenericName      = product.GenericName;
            productDto.INNID            = product.INNID;
            productDto.DosageFormID     = product.DosageFormID;
            productDto.DosageStrengthID = product.DosageStrengthID;
            productDto.DosageUnitID     = product.DosageUnitID;
            productDto.RowGuid          = System.Guid.NewGuid();
            productDto.CreatedByUserID  = product.CreatedByUserID;

            //Load product type from code
            ProductType productType = await _productTypeService.GetAsync(mt => mt.ProductTypeCode == product.ProductTypeCode);

            productDto.ProductTypeID = productType.ID;

            //Construct product manufacturer
            ManufacturerType finishedGoodManufacturer = await _manufacturerTypeService.GetAsync(mt => mt.ManufacturerTypeCode == "FIN_PROD_MANUF");

            productDto.ProductManufacturers = new List <ProductManufacturer> ()
            {
                new ProductManufacturer()
                {
                    ManufacturerAddressID = product.ManufacturerAddressID,
                    ManufacturerTypeID    = finishedGoodManufacturer?.ID
                }
            };

            //Construct Product Presentation
            productDto.Presentations = product.Presentations;

            //Construct Product MD presentation if product type is medical device
            productDto.MDModelSizes = product.MDModelSizes;
            //Construct Supplier Product

            SupplierProduct supProduct = new SupplierProduct()
            {
                SupplierID = product.SupplierID,
                Product    = productDto
            };

            return(supProduct);
        }
Exemple #3
0
        public async Task <ApiResponse> CreateProduct([FromBody] ProductBusinessModel product)
        {
            var result = await _productService.CreateProduct(product);

            return(result);
        }