Post by bostoncl21 on Jun 9, 2015 20:49:33 GMT
in models i get the following
c" cartmodels.cs
c" productmodel.cs
c" producttypemodel.cs
below u can see
GarageEntities db = new GarageEntities();
and this is always coming up red underlined in all 3 models above
i am new to this can anyone help me please?
thanks bostoncl21.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
/// <summary>
/// Summary description for Cartmodel
/// </summary>
public class Cartmodel
{
public string InsertCart(Cart cart)
{
try
{
GarageEntities db = new GarageEntities();
db.Carts.Add(cart);
db.SaveChanges();
return cart.DatePurchased + "was succesfully inserted";
}
catch (Exception e)
{
return "Error:" + e;
}
}
public string UpdateCart(int id, Cart cart)
{
try
{
GarageEntities db = new GarageEntities();
//Fetch object from db
Cart p = db.Cart.Find(id);
p.DatePurchased = cart.DatePurchased;
p.ClientID = cart.ClientID;
p.Amount = cart.Amount;
p.IsInCart = cart.IsInCart;
p.ProductID = cart.ProductID;
db.SaveChanges();
return cart.DatePurchased + "was succesfully updated";
}
catch (Exception e)
{
return "Error:" + e;
}
}
public string DeleteCart(int id)
{
try
{
GarageEntities db = new GarageEntities();
Cart cart = db.Carts.Find(id);
db.Carts.Attach(cart);
db.Carts.Remove(cart);
db.SaveChanges();
return cart.DatePurchased + "was succesfully deleted";
}
catch (Exception e)
{
return "Error:" + e;
}
}
}
c" cartmodels.cs
c" productmodel.cs
c" producttypemodel.cs
below u can see
GarageEntities db = new GarageEntities();
and this is always coming up red underlined in all 3 models above
i am new to this can anyone help me please?
thanks bostoncl21.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
/// <summary>
/// Summary description for Cartmodel
/// </summary>
public class Cartmodel
{
public string InsertCart(Cart cart)
{
try
{
GarageEntities db = new GarageEntities();
db.Carts.Add(cart);
db.SaveChanges();
return cart.DatePurchased + "was succesfully inserted";
}
catch (Exception e)
{
return "Error:" + e;
}
}
public string UpdateCart(int id, Cart cart)
{
try
{
GarageEntities db = new GarageEntities();
//Fetch object from db
Cart p = db.Cart.Find(id);
p.DatePurchased = cart.DatePurchased;
p.ClientID = cart.ClientID;
p.Amount = cart.Amount;
p.IsInCart = cart.IsInCart;
p.ProductID = cart.ProductID;
db.SaveChanges();
return cart.DatePurchased + "was succesfully updated";
}
catch (Exception e)
{
return "Error:" + e;
}
}
public string DeleteCart(int id)
{
try
{
GarageEntities db = new GarageEntities();
Cart cart = db.Carts.Find(id);
db.Carts.Attach(cart);
db.Carts.Remove(cart);
db.SaveChanges();
return cart.DatePurchased + "was succesfully deleted";
}
catch (Exception e)
{
return "Error:" + e;
}
}
}