Esempio n. 1
0
        /// <summary>
        /// Get Product Attribute Details by ProductAttributeID
        /// </summary>
        /// <param name="ProductAttributeID"></param>
        /// <returns></returns>
        public IEnumerable <ProductSizeAndPriceViewModel> ProductAttributeDetails(int ProductAttributeID)
        {
            IList <ProductSizeAndPriceViewModel> _productSizeAndPrices = new List <ProductSizeAndPriceViewModel>();

            using (var command = Context.Database.GetDbConnection().CreateCommand())
            {
                command.CommandText = "sp_getProductAttributeDetails";
                command.CommandType = System.Data.CommandType.StoredProcedure;

                var parameter = new SqlParameter("ProductAttributeID", ProductAttributeID);
                command.Parameters.Add(parameter);
                this.Context.Database.OpenConnection();

                using (var reader = command.ExecuteReader())
                {
                    while (reader.Read())
                    {
                        ProductSizeAndPriceViewModel _productSizeAndPrice = new ProductSizeAndPriceViewModel
                        {
                            Description          = Common.SafeGetString(reader, "Description"),
                            ProductThicknessName = Common.SafeGetString(reader, "ProductThicknessName"),
                            Column80             = Common.SafeGetString(reader, "80"),
                            Column84             = Common.SafeGetString(reader, "84"),
                            Column90             = Common.SafeGetString(reader, "90"),
                            Column96             = Common.SafeGetString(reader, "96"),
                            Column108            = Common.SafeGetString(reader, "108"),
                        };
                        _productSizeAndPrices.Add(_productSizeAndPrice);
                    }
                }
                this.Context.Database.CloseConnection();
            }

            return(_productSizeAndPrices);
        }
        public async Task <IActionResult> SaveProductSizeAndPrice(ProductSizeAndPriceViewModel model)
        {
            try
            {
                var response = false;

                // Call Post Method to Create New Product Size and Price
                if (model.FormAction.ToLower() == "create")
                {
                    model = await generateAPIResponse.ProductSizeAndPriceViewRepo.SaveModel("ProductSizeAndPrice", model);

                    if (model.ProductSizeAndPriceID != 0)
                    {
                        response = true;
                    }
                }
                // Call Put Method to Update Existing Product Attribute Details
                else
                {
                    response = await generateAPIResponse.ProductSizeAndPriceViewRepo.Update("ProductSizeAndPrice/" + model.ProductSizeAndPriceID, model);
                }

                if (response)
                {
                    return(Ok(model.ProductSizeAndPriceID));
                }
                else
                {
                    ViewBag.Message = null;
                }
            }
            catch (Exception ex)
            {
                ViewBag.Message = "Something went wrong: " + ex.Message;
            }
            return(StatusCode(500));
        }