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

When I use Ctrl + .[dot], it ask me to generate class. But I already created tha

ID: 3583651 • Letter: W

Question

When I use Ctrl + .[dot], it ask me to generate class. But I already created that class. Can you tell me how to I solve this name space problem?

ManageProductType.aspx.cs

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

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>
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 C Debug Any CPU Solution Explorer Manage Product Types.aspx.cs X ManageProductTypes.aspx Pages Management ManageProduct btnSubmit Click (object sender, Event Search Solution Explorer (Ctrl+:) BannerCar,jpg public pa rtial class Pages Management ManageProductTypes eb.UI system. Page 4 Models CartModel.cs protected void Page Load (object sender, EventArgs e CH: ProductModel.cs CH Product Type MModel.cs Pages protected void btnsubmit Click (object sende EventArgs Management D Manage Products.aspx //ProductType Model Product Type pt ne ProductTypeModel. ProductType ManageProductTypes.aspx ProductT Model model ne ProductT de l() t Manage ProductTypes.asp Create ProductT ct Type D About .aspx Generate class for "ProductTypeModel Styles Generate new type D E MasterPage,master ProductType createProduct Type() private Solution Explorer Team Explorer Class View ProductType w ProductType ne Properties p Nam txtName. Text; 100% Error List Search Error List 6 Errors 0 Messages Line Column proiect Description X1 Manage ProductTypes 19 he type or namespace name Product TypeModel' could not be found (are you missing a using directive or an assembly reference?) 2 The type or namespace name Manage ProductTypes 19 ProductType Model could not be found (are you Error List Output Ready Ln 19 Col 9 Ch9 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;
    }
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote