Ejemplo n.º 1
0
 public void Insert(Product item)
 {
     //log the date time created
     item.Created = DateTime.Now;
     _db.Product.Add(item);
     _db.SaveChanges();
 }
Ejemplo n.º 2
0
 public void Update(Product item)
 {
     var dbItem = _db.Product.FirstOrDefault(p => p.Id == item.Id);
     dbItem.Title = item.Title;
     dbItem.Description = item.Description;
     dbItem.Price = item.Price;
     //log the date time updated
     dbItem.Updated = DateTime.Now;
 }
Ejemplo n.º 3
0
 public void Update(Product item)
 {
     if (item == null)
         throw new ArgumentNullException("You cannot update a null product");
     var target = Products.FirstOrDefault(x => x.Id == item.Id);
     target.Title = item.Title;
     target.Price = item.Price;
     target.Updated = DateTime.Now;
 }
Ejemplo n.º 4
0
 public static ProductDTO MapProductToDTO(Product product)
 {
     return new ProductDTO
     {
         Id = product.Id,
         Title = product.Title,
         Price = product.Price,
         Description = product.Description
     };
 }
Ejemplo n.º 5
0
 public static ProductViewModel MapProductToModel(Product product)
 {
     return new ProductViewModel
     {
         Id = product.Id,
         Title = product.Title,
         Price = product.Price,
         Description = product.Description
     };
 }
Ejemplo n.º 6
0
 public void Insert(Product item)
 {
     if (item == null)
         throw new ArgumentNullException("You cannot insert a null product");
     //should define the Id property manually
     var last = Products.Max(x => (int?)x.Id) ?? 0;
     item.Id = last + 1;
     item.Created = DateTime.Now;
     Products.Add(item);
 }
Ejemplo n.º 7
0
 public void Update(Product item)
 {
     var dbItem = db.Product.FirstOrDefault(p => p.Id == item.Id);
     if (dbItem == null)
         throw new ArgumentNullException("Product does not exists");
     dbItem.Title = item.Title;
     dbItem.Description = item.Description;
     dbItem.Price = item.Price;
     //log the date time updated
     dbItem.Updated = DateTime.Now;
     db.SaveChanges();
 }