Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I am getting error when trying to import ProductTypeModel.cs file into ManagePro

ID: 3583652 • Letter: I

Question

I am getting error when trying to import ProductTypeModel.cs file into ManageProductType.aspx.cs file.

---------------------------------------------

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using ProductTypeModel;


public partial class Pages_Management_ManageProductTypes : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void btnSubmit_Click(object sender, EventArgs e)
    {
        //ProductTypeModel.ProductType pt = new ProductTypeModel.ProductType();
        ProductTypeModel model = new ProductTypeModel();
        ProductType pt = CreateProductType();

        lblResult.Text = model.InsertProductType(pt);
    }

    private ProductType createProductType()
    {
        ProductType p = new ProductType();
        p.Name = txtName.Text;

        return p;
    }
}

ProductTypeModel.cs

---------------------------------------

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

/// <summary>
/// Summary description for ProductTypeTypeModel
/// </summary>
namespace ProductTypeModel
{
    public class ProductTypeModel
    {
        public string InsertProductType(ProductType productType)
        {
            try
            {
                GarageDBEntities db = new GarageDBEntities();
                db.ProductTypes.Add(productType);
                db.SaveChanges();

                return productType.Name + "was successfully inserted";
            }
            catch (Exception e)
            {
                return "Error:" + e;
            }
        }

        public string UpdateProductType(int id, ProductType productType)
        {
            try
            {
                GarageDBEntities db = new GarageDBEntities();
                // Fetch object from db
                ProductType p = db.ProductTypes.Find(id);

                p.Name = productType.Name;

                db.SaveChanges();
                return productType.Name + "was successfully updated";
            }
            catch (Exception e)
            {
                return "Error:" + e;
            }

        }

        public string DeleteProductType(int id)
        {
            try
            {
                GarageDBEntities db = new GarageDBEntities();
                ProductType productType = db.ProductTypes.Find(id);

                db.ProductTypes.Attach(productType);
                db.ProductTypes.Remove(productType);
                db.SaveChanges();

                return productType.Name + "was successfully deleted";
            }
            catch (Exception e)
            {
                return "Error:" + e;
            }
        }
    }
}

X GarageManage Microsoft visual Studio (Administrator) J Quick Launch (Ctrl+Q) FILE EDIT VIEW WEBSITE BUILD DEBUG TEAM TOOLS TEST ANALYZE WINDOW HELP Ha s K Firefox Debug Solution Explorer Manage Product Types.aspx.cs X Manage Product lypes.aspx 2. Pages Management ManageProduct Page Load(object sender, EventArgs E using System Search Solution Explorer (Ctrl+ g system Collections .Generic; using System.Linq; Solution 'GarageManager' project) using System. eb 4 e Garage Manager using System. eb.UI App Code using System. eb.UI ebControls Class Diagram.cd using ProductT Model D E Model. Context,tt S Model edmx D Model.tt El public partial class Pages Management ManageProductTypes system. eb.UI Page protected void Page Load (object sende EventArgs mages Products BannerCar,jpg Models E protected void btnsubmit Click (object sende EventArgs e) CH: CartModel.cs CH: ProductModel.cs //ProductType Model Product Type pt ne ProductTypeModel. ProductType ProductT Model model ProductT de l() Solution Explorer Team Explorer Class View ne The type or namespace name 'ProductTypeModel could not be found (are you missing a using directive or an assembly reference?) lblResult model. Product Type (pt) Te Insert 100% Error List Search Error List 9 Errors 0 Messages Description File Column Project ne X1 The name Directory" does not exist in the cu ent ManageProducts.aspx 21 context 2 The type or namespace name ArrayList' could not ManageProducts.aspx 22 be found (are u missing a using directive or assembly reference? The not Error List Output Item(s) Saved Ln 9 Col 1 Ch 1 NS

Explanation / Answer

You need to declare namespace in the file which class will be refernced in other files

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

/// <summary>
/// Summary description for ProductTypeTypeModel
/// </summary>

namespace productTypeModelName

{
public class ProductTypeModel
{
    public string InsertProductType(ProductType productType)
    {
        try
        {
            GarageDBEntities db = new GarageDBEntities();
            db.ProductTypes.Add(productType);
            db.SaveChanges();

            return productType.Name + "was successfully inserted";
        }
        catch (Exception e)
        {
            return "Error:" + e;
        }
    }

    public string UpdateProductType(int id, ProductType productType)
    {
        try
        {
            GarageDBEntities db = new GarageDBEntities();
            // Fetch object from db
            ProductType p = db.ProductTypes.Find(id);

            p.Name = productType.Name;

            db.SaveChanges();
            return productType.Name + "was successfully updated";
        }
        catch (Exception e)
        {
            return "Error:" + e;
        }

    }

    public string DeleteProductType(int id)
    {
        try
        {
            GarageDBEntities db = new GarageDBEntities();
            ProductType productType = db.ProductTypes.Find(id);

            db.ProductTypes.Attach(productType);
            db.ProductTypes.Remove(productType);
            db.SaveChanges();

            return productType.Name + "was successfully deleted";
        }
        catch (Exception e)
        {
            return "Error:" + e;
        }
    }
}

}

Then you need to add this namespace in which you're referencing those classes

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using productTypeModelName;

public partial class Pages_Management_ManageProductTypes : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void btnSubmit_Click(object sender, EventArgs e)
    {
        //ProductTypeModel.ProductType pt = new ProductTypeModel.ProductType();
        ProductTypeModel model = new ProductTypeModel();
        ProductType pt = CreateProductType();

        lblResult.Text = model.InsertProductType(pt);
    }

    private ProductType createProductType()
    {
        ProductType p = new ProductType();
        p.Name = txtName.Text;

        return p;
    }
}