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 Int64 GetTotalRecordCount()
 {
     using (var bikestoreContext = new SampleAutomotiveEntities())
     {
         return(bikestoreContext.Customers.Where(x => x.IsActive == true).Count());
     }
 }
 public Int64 GetTotalRecordCount()
 {
     using (var bikestoreContext = new SampleAutomotiveEntities())
     {
         return(bikestoreContext.Products.Count());
     }
 }
示例#4
0
 public List <ProductCategory> GetAll()
 {
     using (var bikestorecontext = new SampleAutomotiveEntities())
     {
         List <ProductCategory> categories = bikestorecontext.Categories
                                             .Select(x => new ProductCategory
         {
             CategoryId   = x.category_id,
             CategoryName = x.category_name
         }).ToList();
         return(categories);
     }
 }
示例#5
0
 public List <BrandModel> GetAll()
 {
     using (var bikestorecontext = new SampleAutomotiveEntities())
     {
         List <BrandModel> brands = bikestorecontext.Brands
                                    .Where(x => x.IsActive == true)
                                    .Select(x => new BrandModel
         {
             BrandId   = x.brand_id,
             BrandName = x.brand_name
         }).ToList();
         return(brands);
     }
 }
 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);
 }
        public List <ProductModel> GetAll(SearchModel search)
        {
            using (var bikestorecontext = new SampleAutomotiveEntities())
            {
                // IQueryable<Product> product = bikestorecontext.Products.ToList();
                IEnumerable <Product> product = bikestorecontext.Products.ToList();

                if (!string.IsNullOrEmpty(search.searchItem))
                {
                    product = product.Where(x => x.product_name.Contains(search.searchItem));
                }

                if (!string.IsNullOrEmpty(search.orderByCommand))
                {
                    if (search.orderByCommand == "asc")
                    {
                        product = product.OrderBy(x => x.product_name);
                    }
                    else
                    {
                        product = product.OrderByDescending(x => x.product_name);
                    }
                }

                //product = product
                //.Skip(search.currentIndex * search.TotalRecordsPerPage)
                //.Take(search.TotalRecordsPerPage);


                var products = (from prod in bikestorecontext.Products
                                join brd in bikestorecontext.Brands on prod.brand_id equals brd.brand_id
                                join cat in bikestorecontext.Categories on prod.category_id equals cat.category_id
                                select new ProductModel
                {
                    ProductId = prod.product_id,
                    ProductName = prod.product_name,
                    BrandName = brd.brand_name,
                    CategoryName = cat.category_name,
                    ModelYear = prod.model_year,
                    ListPrice = prod.list_price
                }).OrderBy(x => x.ProductName).Skip(search.currentIndex * search.TotalRecordsPerPage)
                               .Take(search.TotalRecordsPerPage).ToList();

                return(products);
            }
        }
示例#8
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 CustomerModel GetCustomerDetails(int customerId)
        {
            using (var bikestoreContext = new SampleAutomotiveEntities())
            {
                Customer customer = bikestoreContext.Customers.Where(x => x.customer_id == customerId).FirstOrDefault();

                if (customer != null)
                {
                    CustomerModel objCustomerModel = new CustomerModel();
                    objCustomerModel.CustomerId = customer.customer_id;
                    objCustomerModel.FirstName  = customer.first_name;
                    objCustomerModel.LastName   = customer.last_name;
                    objCustomerModel.Phone      = customer.phone;
                    objCustomerModel.ZipCode    = customer.zip_code;

                    return(objCustomerModel);
                }
                return(null);
            }
        }
 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 List <ProductModel> ListOfProducts()
        {
            using (var bikestorecontext = new SampleAutomotiveEntities())
            {
                var products = (from prod in bikestorecontext.Products
                                join brd in bikestorecontext.Brands on prod.brand_id equals brd.brand_id
                                join cat in bikestorecontext.Categories on prod.category_id equals cat.category_id
                                select new ProductModel
                {
                    ProductId = prod.product_id,
                    ProductName = prod.product_name,
                    BrandName = brd.brand_name,
                    CategoryName = cat.category_name,
                    ModelYear = prod.model_year,
                    ListPrice = prod.list_price
                }).ToList();

                return(products);
            }
        }
        public List <CustomerModel> GetAll(SearchModel searchModel)
        {
            using (var bikestoreContext = new SampleAutomotiveEntities())
            {
                IQueryable <Customer> customer = bikestoreContext.Customers.Where(x => x.IsActive == true);

                if (!string.IsNullOrEmpty(searchModel.searchItem))
                {
                    customer = customer.Where(x => x.first_name.Contains(searchModel.searchItem));
                }

                if (!string.IsNullOrEmpty(searchModel.orderByCommand))
                {
                    if (searchModel.orderByCommand == "asc")
                    {
                        customer = customer.OrderBy(x => x.first_name);
                    }
                    else
                    {
                        customer = customer.OrderByDescending(x => x.first_name);
                    }
                }

                customer = customer
                           .Skip(searchModel.currentIndex * searchModel.TotalRecordsPerPage)
                           .Take(searchModel.TotalRecordsPerPage);

                var Result = customer.Select(x => new CustomerModel
                {
                    DT_RowId   = System.Data.Entity.SqlServer.SqlFunctions.StringConvert((double)x.customer_id),
                    DT_RowData = new { pkey = x.customer_id },
                    CustomerId = x.customer_id,
                    FirstName  = x.first_name,
                    LastName   = x.last_name,
                    Phone      = x.phone,
                    Email      = x.email
                }).ToList();

                return(Result);
            }
        }
 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);
     }
 }