示例#1
0
 public void UpdateCategory(Category category)
 {
     using (var context = new EContext())
     {
         context.Entry(category).State = System.Data.Entity.EntityState.Modified;
         context.SaveChanges();
     }
 }
示例#2
0
 public void UpdateProduct(Product product)
 {
     using (var context = new EContext())
     {
         context.Entry(product).State = System.Data.Entity.EntityState.Modified;
         context.SaveChanges();
     }
 }
示例#3
0
        public void SaveProduct(Product product)
        {
            using (var context = new EContext())
            {
                context.Entry(product.Category).State = System.Data.Entity.EntityState.Unchanged;

                context.Products.Add(product);
                context.SaveChanges();
            }
        }
示例#4
0
        public bool UpdateOrderStatus(int Id, string status)
        {
            using (var context = new EContext())
            {
                var order = context.Orders.Find(Id);

                order.Status = status;

                context.Entry(order).State = EntityState.Modified;

                return(context.SaveChanges() > 0);
            }
        }
示例#5
0
        public bool Eliminar(Expression <Func <T, bool> > predicate)
        {
            bool blResultado = false;

            using (EContext context = new EContext())
            {
                try
                {
                    var entities = context.Set <T>().Where(predicate).ToList();
                    entities.ForEach(x => context.Entry(x).State = EntityState.Deleted);
                    context.SaveChanges();
                    blResultado = true;
                }
                catch (Exception ex)
                {
                    blResultado = false;
                    throw new Exception(ex.Message);
                }
            }
            return(blResultado);
        }
示例#6
0
        public bool Eliminar(T entity)
        {
            bool blResultado = false;

            using (EContext context = new EContext())
            {
                try
                {
                    context.Entry(entity).State = EntityState.Deleted;
                    context.SaveChanges();

                    blResultado = true;
                }
                catch (Exception ex)
                {
                    blResultado = false;
                    throw new Exception(ex.Message);
                }
            }
            return(blResultado);
        }
示例#7
0
        public async Task <bool> Save(Vehicle vehicle)
        {
            try
            {
                _context.Entry(vehicle).State = string.IsNullOrEmpty(vehicle.Id) ? EntityState.Added : EntityState.Modified;
                _context.Vehicles.Add(vehicle);

                int affected = await _context.SaveChangesAsync();

                if (affected > 0)
                {
                    return(true);
                }
            }
            catch (Exception ex)
            {
                //Exception (ex) should be logged if required ..
                //Type of exceptions can be also identified and proper reaction is gonna be handled according to requirements
            }

            return(false);
        }