Can you tell me why I am getting error on this line as the class is already exis
ID: 3583638 • Letter: C
Question
Can you tell me why I am getting error on this line as the class is already exist in the Model folder.
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 model = new ProductTypeModel();
}
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;
}
}
}
Explanation / Answer
you are getting this error because you are not imported the class ProductTypeModel in your namespace. In order to resolve this you need to resolve the dependency, for that in visual studio just right click and select the resolve dependency, that will automatically reolve this kind of dependency problem.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.