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 id1, int id2) { using (var _context = new AnalogyContext()) { var entity = Find(id1, id2); _context.Entry(entity).State = EntityState.Deleted; _context.SaveChanges(); } }