public void Sync() { MedicalContext clientRepo = new MedicalContext(); Medical2Context serverRepo = new Medical2Context(); List<Medicine> clientsMedicines = clientRepo.Medicines.OrderBy(x=>x.Id).ToList(); List<Medicine> serverMedicines = serverRepo.Medicines.OrderBy(x => x.Id).ToList(); foreach (Medicine org in clientsMedicines) { bool isExist = false; foreach (Medicine target in serverMedicines) { if (org.Id != target.Id) continue; isExist = true; update(org, target); Console.WriteLine("Update: " + org.Id); } if (isExist) continue; clientRepo.Medicines.Remove(org); Console.WriteLine("Delete: " + org.Id); } foreach (Medicine target in serverMedicines) { bool isExist = false; foreach (Medicine org in clientsMedicines) { if (org.Id != target.Id) continue; isExist = true; } if (isExist) continue; Medicine news = clone(target); clientRepo.Medicines.Add(news); Console.WriteLine("Add: " + target.Id); } clientRepo.SaveChanges(); }
protected readonly MedicalContext Context; //= new MedicalContext(); //protected readonly FigureContext FigureContext = new FigureContext(); public RepositoryBase(Boolean serverContext) { this.Context = serverContext ? new Medical2Context() : new MedicalContext(); }
protected readonly MedicalContext Context; //= new MedicalContext(); #endregion Fields #region Constructors //protected readonly FigureContext FigureContext = new FigureContext(); public RepositoryBase(Boolean serverContext) { this.Context = serverContext ? new Medical2Context() : new MedicalContext(); }