//check all product fields for validity
        public bool ChkProductForAdd(Product p)
        {
            int errCnt = 0;
            if (String.IsNullOrEmpty(p.FirstName ))
            { errCnt++; ModelNumberBrush = errorBrush; }
            else ModelNumberBrush = okBrush;
            if (String.IsNullOrEmpty(p.LastName))
            { errCnt++; ModelNumberBrush = errorBrush; }
            else ModelNumberBrush = okBrush;
            if (String.IsNullOrEmpty(p.EmailID ))
            { errCnt++; ModelNameBrush = errorBrush; }
            else ModelNameBrush = okBrush;
            //if (String.IsNullOrEmpty(p.Dob))
            //{ errCnt++; CategoryNameBrush = errorBrush; }
            //else CategoryNameBrush = okBrush;

            //if (String.IsNullOrEmpty(p.Address ))
            //{ errCnt++; CategoryNameBrush = errorBrush; }
            //else CategoryNameBrush = okBrush;

            if (String.IsNullOrEmpty(p.PhNo))
            { errCnt++; CategoryNameBrush = errorBrush; }
            else CategoryNameBrush = okBrush;

            if (errCnt == 0) { Status = "OK"; return true; }
            else { Status = "ADD, missing or invalid fields."; return false; }
        }
        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;
        }
 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);
 }
 private void SearchProductDisplay()
 {
     isSelected = false;
     stat.NoError();
     DisplayedProduct = new Product();
     App.Messenger.NotifyColleagues("ProductSearch");
 }
        private void GetProducts()
        {
            isSelected = false;
            stat.NoError();
            DisplayedProduct = new Product();

            App.Messenger.NotifyColleagues("GetProducts");
        }
 public void ProcessProduct(Product p)
 {
     if (p == null) { /*DisplayedProduct = null;*/  isSelected = false; return; }
     Product temp = new Product();
     temp.CopyProduct(p);
     DisplayedProduct = temp;
     isSelected = true;
     stat.NoError();
 }
 public SqlProduct(Product p)
 {
     ContactID = p._ContactId ;
     FirstName  = p.FirstName ;
     LastName = p.LastName;
     EmailID = p.EmailID;
     PhNo = p.PhNo;
     State = p.State;
     City = p.City;
 }
 public void CopyProduct(Product p)
 {
     this._contactId = p._ContactId ;
     this.FirstName  = p.FirstName;
     this.LastName = p.LastName;
     this.EmailID  = p.EmailID ;
     this.PhNo = p.PhNo;
     this.State  = p.State ;
     this.City  = p.City ;
 }