public void Save(T entity) { //TODO: provisório tentar achar uma forma mais eficiente para colocar no contexto, se for uma importação if (entity.Id == 0) { CurrentDbSet.Add(entity); } else { var entry = GetDbContext.ChangeTracker.Entries().FirstOrDefault(x => ((ILGTEntity)x.Entity).Id == entity.Id); if (entry != null) { var concretType = entity.GetType(); var propertysToClone = concretType.GetProperties().Where(x => !x.PropertyType.IsNested && x.CanWrite).ToList(); foreach (var p in propertysToClone) { p.SetValue(entry.Entity, p.GetValue(entity, new object[0]), new object[0]); } } else { GetDbContext.Entry(entity).State = EntityState.Modified; } } this.SaveChanges(); }
private static void SetLastTimeEmailWasChecked() { try { var getDbContext = new GetDbContext(); var context = getDbContext.ReturnDbContext(); var emailConfigRepo = new EmailConfigRepository(context, null); emailConfigRepo.SetLastLoadDate(DateTime.Now); } catch (Exception ex) { Console.WriteLine("Failed to get GetLastTimeEmailWasChecked!" + ex.Message); } }
private static string GetLastTimeEmailWasChecked() { try { var getDbContext = new GetDbContext(); var context = getDbContext.ReturnDbContext(); var emailConfigRepo = new EmailConfigRepository(context, null); string lastLoad = emailConfigRepo.GetLastLoadDate().ToString("yyyy-MM-dd"); return(lastLoad); } catch (Exception ex) { Console.WriteLine("Failed to get GetLastTimeEmailWasChecked!" + ex.Message); return(null); } }
public NoteRepository(IOptions <SettingModel> settings) { _context = new GetDbContext(settings); }
protected virtual void SaveChanges() { GetDbContext.ChangeTracker.DetectChanges(); GetDbContext.SaveChanges(); }