public bool AddProduct(Product displayP)
        {
            hasError = false;
            try
            {
                SqlProduct p = new SqlProduct(displayP);

                int? newProductId = 0;
                ContactDBEntities3 db = new ContactDBEntities3();

                Contact e = new Contact() {FirstName  = p.FirstName,LastName=p.LastName , EmailID = p.EmailID, State = p.State, City = p.City,PhNo=p.PhNo  };
                // e.Vacations.Add(v);
                db.Contacts.Add(e);
                db.SaveChanges();

                p.ContactID  =1;
                displayP.ProductAdded2DB(p);    //update corresponding Product ProductId using SqlProduct
            }
            catch (Exception ex)
            {
                errorMessage = "Add error, " + ex.Message;
                hasError = true;
            }
            return !hasError;
        }
 //Creating a new product in the DB assigns the ProductId
 //Update the ProductId from the value in the corresponding SqlProduct
 public void ProductAdded2DB(SqlProduct sqlProduct)
 {
     this._contactId = sqlProduct.ContactID ;
 }
 public bool UpdateProduct(Product displayP,int contactId)
 {
     try
     {
         SqlProduct p1 = new SqlProduct(displayP);
         ContactDBEntities3 db = new ContactDBEntities3();
         Contact con = db.Contacts.SingleOrDefault(p => p.ContactID  == contactId);
         con.FirstName = p1.FirstName;
         con.LastName = p1.LastName;
         con.EmailID = p1.EmailID;
         con.PhNo = p1.PhNo;
         con.State = p1.State;
         con.City = p1.City;
         db.SaveChanges();
     }
     catch (Exception ex)
     {
         errorMessage = "Update error, " + ex.Message;
         hasError = true;
     }
     return (!hasError);
 }
Example #4
0
 //Creating a new product in the DB assigns the ProductId
 //Update the ProductId from the value in the corresponding SqlProduct
 public void ProductAdded2DB(SqlProduct sqlProduct)
 {
     this._contactId = sqlProduct.ContactID;
 }