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