Пример #1
0
        public Product SaveProduct(Product product)
        {
            KendoPOCEntities context = new KendoPOCEntities();
            Product result = null;

            product.StatusType = 1;
            context.Entry<Product>(product).State = (product.Id == 0 ? EntityState.Added : EntityState.Modified);

            if (context.Entry<Product>(product).State == EntityState.Added)
            {
                product.CreationUserId = "SuperUser";
                product.CreationTs = DateTime.Now;
                context.Product.Add(product);
            }
            else
            {
                product.LastChangeUserId = "SuperUser";
                product.LastChangeTs = DateTime.Now;
            }
            int rowsAffected = context.SaveChanges();

            if (rowsAffected != 0)
            {
                result = product;
            }

            return result;
        }
Пример #2
0
        public IEnumerable<Product> GetAllProducts()
        {
            KendoPOCEntities context = new KendoPOCEntities();

            var productsList = context.Product.Include("Category").Include("UnitofMeasure");
            //var productsList = context.Product;
            return productsList.AsEnumerable();
        }
Пример #3
0
        public bool DeleteProduct(int id)
        {
            KendoPOCEntities context = new KendoPOCEntities();

            var product = new Product() { Id = id };

            context.Entry<Product>(product).State = EntityState.Deleted;
            int rowsAffected = context.SaveChanges();

            return (rowsAffected == 1);
        }
Пример #4
0
 public Product GetProductById(int id)
 {
     KendoPOCEntities context = new KendoPOCEntities();
     var result = context.Product.FirstOrDefault(item => item.Id == id);
     return result;
 }
Пример #5
0
        public IEnumerable<Category> GetAllCategory()
        {
            KendoPOCEntities context = new KendoPOCEntities();

            return context.Category.AsEnumerable();
        }
Пример #6
0
        public IEnumerable<UnitofMeasure> GetAllunits()
        {
            KendoPOCEntities context = new KendoPOCEntities();

            return context.UnitofMeasure.AsEnumerable();
        }