public List<Product> GetProductList() { List<Product> products = new List<Product>(); using (var context = Config.context) { try { var data = context.C_Product.Select(i => i); foreach (C_Product item in data) { Product product = new Product(); product.Id = item.id; product.Name = item.name; product.Description = item.description; product.Price = item.price; product.Timestamp = item.timestamp; products.Add(product); } } catch (Exception ex) { // log here } } return products; }
public Product Convert(C_Product cProduct) { Product product = new Product(); product.Id = cProduct.id; product.Name = cProduct.name; product.Description = cProduct.description; product.Price = cProduct.price; product.Timestamp = cProduct.timestamp; return product; }
public C_Product Convert(Product product) { C_Product cProduct = new C_Product(); cProduct.id = product.Id; cProduct.name = product.Name; cProduct.description = product.Description; cProduct.price = product.Price; cProduct.timestamp = product.Timestamp; return cProduct; }
public Product FindProductById(int id) { Product product = new Product(); using (var context = Config.context) { try { var data = context.C_Product.Single(i => i.id == id); return Convert(data); } catch (Exception ex) { // log here } } return product; }
public Product FindProductById(int id) { Product product = new Product(); using (var context = Config.context) { try { var data = context.C_Product.Single(i => i.id == id); product.Id = data.id; product.Name = data.name; product.Description = data.description; product.Price = data.price; product.Timestamp = data.timestamp; } catch (Exception ex) { // log here } } return product; }
public bool Edit(Product product) { /* bool completed = false; using (var context = Config.context) { try { var item = context.C_Product.Single(i => i.id == product.Id); var data = Convert(product); context.SaveChanges(); completed = true; } catch (Exception ex) { // log here } } return completed; */ return false; }
public bool Insert(Product product) { bool completed = false; return completed; }
public bool Remove(Product product) { bool completed = false; using (var context = Config.context) { try { var item = context.C_Product.Single(i => i.id == product.Id); var data = context.C_Product.Remove(item); completed = true; } catch (Exception ex) { // log here } } return completed; }
public bool Insert(Product product) { bool completed = false; using (var context = Config.context) { try { var data = context.C_Product.Add(Convert(product)); context.SaveChanges(); completed = true; } catch (Exception ex) { // log here } } return completed; }