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();
        }
示例#2
0
        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);
            }
        }
示例#3
0
        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);
            }
        }
示例#4
0
 public NoteRepository(IOptions <SettingModel> settings)
 {
     _context = new GetDbContext(settings);
 }
 protected virtual void SaveChanges()
 {
     GetDbContext.ChangeTracker.DetectChanges();
     GetDbContext.SaveChanges();
 }