public int Save(Proof dao) { Proof entity = objDataContext.Proofs.SingleOrDefault(x => x.ProofId.Equals(dao.ProofId)); if (entity != null) { entity.ModifiedAt = DateTimeOffset.Now; objDataContext.Entry(entity).CurrentValues.SetValues(dao); } else { objDataContext.Proofs.Add(dao); } objDataContext.SaveChanges(); return(dao.ProofId); }
public bool Delete(int id) { var objProofFiles = objDataContext.ProofFiles.Where(x => x.ProofId == id); if (objProofFiles != null) { foreach (var item in objProofFiles) { objDataContext.ProofFiles.Remove(item); } } Proof dbEntity = objDataContext.Proofs.Where(x => x.ProofId == id).FirstOrDefault(); if (dbEntity != null) { objDataContext.Proofs.Remove(dbEntity); objDataContext.SaveChanges(); } return(true); }