Esempio n. 1
0
 public void Insert(Product item)
 {
     //log the date time created
     item.Created = DateTime.Now;
     _db.Product.Add(item);
     _db.SaveChanges();
 }
Esempio 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;
 }
Esempio 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;
 }
Esempio n. 4
0
 public static ProductDTO MapProductToDTO(Product product)
 {
     return new ProductDTO
     {
         Id = product.Id,
         Title = product.Title,
         Price = product.Price,
         Description = product.Description
     };
 }
Esempio n. 5
0
 public static ProductViewModel MapProductToModel(Product product)
 {
     return new ProductViewModel
     {
         Id = product.Id,
         Title = product.Title,
         Price = product.Price,
         Description = product.Description
     };
 }
Esempio 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);
 }
Esempio 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();
 }