예제 #1
0
 public void UpdateProduct(Product product)
 {
     using (var context = new MCContext())
     {
         context.Entry(product).State = System.Data.Entity.EntityState.Modified;
         context.SaveChanges();
     }
 }
예제 #2
0
 public void UpdateCategory(Category category)
 {
     using (var context = new MCContext())
     {
         context.Entry(category).State = System.Data.Entity.EntityState.Modified;
         context.SaveChanges();
     }
 }
예제 #3
0
 public void UpdateMedicine(MedicineModel model)
 {
     using (var context = new MCContext())
     {
         context.Entry(model).State = System.Data.Entity.EntityState.Modified;
         context.SaveChanges();
     }
 }
예제 #4
0
        public void SaveProduct(Product product)
        {
            using (var context = new MCContext())
            {
                context.Entry(product.Category).State = System.Data.Entity.EntityState.Unchanged;

                context.Products.Add(product);
                context.SaveChanges();
            }
        }
        public virtual async Task <T> UpdateAsync(T entity)
        {
            var existing = await _context.Set <T>().FirstOrDefaultAsync(x => x.Id == entity.Id && !x.Deleted).ConfigureAwait(false);

            if (existing is null)
            {
                throw new KeyNotFoundException($"Can't find object {typeof(T)}, with id {entity.Id}");
            }

            _context.Entry(existing).CurrentValues.SetValues(entity);

            return(existing);
        }