TechGuy
TechGuy

Reputation: 4570

Cannot implicitly convert type but already it's Converted

Cannot implicitly convert type problem.but in here it's converted & assign.Can anyone tell me whats wrong here ? here i have post whole code for it.

 [HttpGet]
    public ActionResult AddProduct(int? id)
    {
        Models.ProductsModels.Products product = new Models.ProductsModels.Products();

        ViewBag.ListOfCategories = new SelectList(_cat.GetCategory(), "CategoryId", "CategoryName");
        ViewBag.ListOfBrands = new SelectList(_brad.GetAllBrands(), "BrandId", "BrandName");

        int productId = id ?? 0;

        if (id.HasValue)
        {
            ICS.Data.Product _prod = new ICS.Data.Product();
            product = (new ProductController()).GetProductById(productId);
            product.ProductId = _prod.ProductId;
            product.ProductName = _prod.ProductName;
            product.CategoryId = _prod.Category_CategoryId;
            product.BrandId = _prod.Brand_BrandId;
            product.PriceSettings = _prod.IsFixed;
            product.PurchasePrice = (float)_prod.PurchasePrice;
            product.ItemPrice = (float)_prod.ItemPrice;
            product.Vat = (double)_prod.Vat;
            product.WholeSalePrice = (float)_prod.WholeSalePrice;
            product.RetailPrice = (float)_prod.RetailPrice;
            product.Comments = _prod.Comments;         
        }

        return View(product);
    }

finally it's retun to the Product View.

Upvotes: 0

Views: 68

Answers (1)

freshbm
freshbm

Reputation: 5632

Change this in your code:

_prod = (new ProductController()).GetProductById(productId);

Full code:

[HttpGet]
    public ActionResult AddProduct(int? id)
    {
        Models.ProductsModels.Products product = new Models.ProductsModels.Products();

        ViewBag.ListOfCategories = new SelectList(_cat.GetCategory(), "CategoryId", "CategoryName");
        ViewBag.ListOfBrands = new SelectList(_brad.GetAllBrands(), "BrandId", "BrandName");

        int productId = id ?? 0;

        if (id.HasValue)
        {
            ICS.Data.Product _prod = (new ProductController()).GetProductById(productId);
            product.ProductId = _prod.ProductId;
            product.ProductName = _prod.ProductName;
            product.CategoryId = _prod.Category_CategoryId;
            product.BrandId = _prod.Brand_BrandId;
            product.PriceSettings = _prod.IsFixed;
            product.PurchasePrice = (float)_prod.PurchasePrice;
            product.ItemPrice = (float)_prod.ItemPrice;
            product.Vat = (double)_prod.Vat;
            product.WholeSalePrice = (float)_prod.WholeSalePrice;
            product.RetailPrice = (float)_prod.RetailPrice;
            product.Comments = _prod.Comments;         
        }

        return View(product);
    }

Upvotes: 1

Related Questions