public async Task <Models.SqlExpress.Product> CancelProductChanges(Models.SqlExpress.Product item) { var entityToCancel = Context.Entry(item); entityToCancel.CurrentValues.SetValues(entityToCancel.OriginalValues); entityToCancel.State = EntityState.Unchanged; return(item); }
public async Task <Models.SqlExpress.Product> CreateProduct(Models.SqlExpress.Product product) { OnProductCreated(product); Context.Products.Add(product); Context.SaveChanges(); OnAfterProductCreated(product); return(product); }
public async Task <Models.SqlExpress.Product> UpdateProduct(int?id, Models.SqlExpress.Product product) { OnProductUpdated(product); var itemToUpdate = Context.Products .Where(i => i.Id == id) .FirstOrDefault(); if (itemToUpdate == null) { throw new Exception("Item no longer available"); } var entryToUpdate = Context.Entry(itemToUpdate); entryToUpdate.CurrentValues.SetValues(product); entryToUpdate.State = EntityState.Modified; Context.SaveChanges(); OnAfterProductUpdated(product); return(product); }
partial void OnAfterProductUpdated(Models.SqlExpress.Product item);
partial void OnProductGet(Models.SqlExpress.Product item);
partial void OnProductDeleted(Models.SqlExpress.Product item);
partial void OnProductCreated(Models.SqlExpress.Product item);