public bool Add(ProductModel product)
        {
            try
            {
                using (var bikestorecontext = new SampleAutomotiveEntities())
                {
                    Product proobj = new Product();


                    proobj.product_name = product.ProductName;
                    proobj.model_year   = (short)product.ModelYear;
                    proobj.list_price   = product.ListPrice;

                    proobj.brand_id    = product.BrandID;
                    proobj.category_id = product.CategoryID;

                    bikestorecontext.Products.Add(proobj);

                    bikestorecontext.SaveChanges();
                    return(true);
                }
            }
            catch (Exception ex)
            {
                return(false);
            }
        }
 public bool Update(CustomerModel customer)
 {
     using (var bikestoreContext = new SampleAutomotiveEntities())
     {
         Customer ucustomer = bikestoreContext.Customers.Where(x => x.customer_id == customer.CustomerId).FirstOrDefault();
         if (ucustomer != null)
         {
             ucustomer.first_name = customer.FirstName;
             ucustomer.last_name  = customer.LastName;
             ucustomer.phone      = customer.Phone;
             ucustomer.zip_code   = customer.ZipCode;
             bikestoreContext.SaveChanges();
             return(true);
         }
     }
     return(false);
 }
예제 #3
0
 public bool Delete(int brandId)
 {
     try
     {
         using (var bikestoreContext = new SampleAutomotiveEntities())
         {
             Brand brand = bikestoreContext.Brands.Where(x => x.brand_id == brandId).FirstOrDefault();
             if (brand != null)
             {
                 brand.IsActive = false;
                 bikestoreContext.SaveChanges();
             }
             return(true);
         }
     }
     catch (Exception)
     {
         return(false);
     }
 }
 public bool Delete(int customerId)
 {
     try
     {
         using (var bikestoreContext = new SampleAutomotiveEntities())
         {
             Customer customer = bikestoreContext.Customers.Where(x => x.customer_id == customerId).FirstOrDefault();
             if (customer != null)
             {
                 customer.IsActive = false;
                 bikestoreContext.SaveChanges();
             }
             return(true);
         }
     }
     catch (Exception)
     {
         return(false);
     }
 }
 public bool Add(CustomerModel customer)
 {
     try
     {
         using (var bikestoreContext = new SampleAutomotiveEntities())
         {
             Customer custObj = new Customer();
             custObj.first_name = customer.FirstName;
             custObj.last_name  = customer.LastName;
             custObj.phone      = customer.Phone;
             custObj.email      = customer.Email;
             custObj.IsActive   = true;
             custObj.zip_code   = customer.ZipCode;
             bikestoreContext.Customers.Add(custObj);
             bikestoreContext.SaveChanges();
             return(true);
         }
     }
     catch (Exception ex)
     {
         return(false);
     }
 }