Ejemplo n.º 1
0
        public Analogy CreateOrUpdate(Analogy analogy)
        {
            //analogy.Product1.VendorCode = Regex.Replace(analogy.Product1.VendorCode, "[,\\./-]", string.Empty);
            //analogy.Product2.VendorCode = Regex.Replace(analogy.Product2.VendorCode, "[,\\./-]", string.Empty);
            //analogy.Product1.Manufacturer = analogy.Product1.Manufacturer.ToLower();
            //analogy.Product2.Manufacturer = analogy.Product2.Manufacturer.ToLower();
            using (var _context = new AnalogyContext())
            {
                var productRepository = new ProductRepository();
                analogy.Product1   = productRepository.CreateOrUpdate(analogy.Product1);
                analogy.Product2   = productRepository.CreateOrUpdate(analogy.Product2);
                analogy.Product1Id = analogy.Product1.Id;
                analogy.Product2Id = analogy.Product2.Id;

                var existAnalogy = Find(analogy.Product1.Id, analogy.Product2.Id);
                if (existAnalogy != null)
                {
                    _context.Entry(analogy).State = EntityState.Modified;
                    _context.SaveChanges();
                    return(analogy);
                }

                analogy = Create(analogy);
                return(analogy);
            }
        }
 public void Delete(int id)
 {
     using (var _context = new AnalogyContext())
     {
         var entity = _context.Products.Find(id);
         _context.Products.Remove(entity);
         _context.SaveChanges();
     }
 }
 public Product Update(Product entity)
 {
     using (var _context = new AnalogyContext())
     {
         _context.Products.AddOrUpdate(entity);
         _context.SaveChanges();
         return(entity);
     }
 }
Ejemplo n.º 4
0
 public void Delete(int id1, int id2)
 {
     using (var _context = new AnalogyContext())
     {
         var entity = Find(id1, id2);
         _context.Entry(entity).State = EntityState.Deleted;
         _context.SaveChanges();
     }
 }
Ejemplo n.º 5
0
 public Analogy Create(Analogy entity)
 {
     using (var _context = new AnalogyContext())
     {
         _context.Products.Attach(entity.Product1);
         _context.Products.Attach(entity.Product2);
         entity = _context.Analogues.Add(entity);
         _context.SaveChanges();
         return(entity);
     }
 }
        public Product CreateOrUpdate(Product product)
        {
            using (var _context = new AnalogyContext())
            {
                var entity = Get(product.VendorCode, product.Manufacturer);
                if (entity != null)
                {
                    return(entity);
                }

                if (_context.Products.Find(product.Id) != null)
                {
                    return(Update(product));
                }

                _context.Products.Add(product);
                _context.SaveChanges();
                return(product);
            }
        }