Exemple #1
0
 public void LectoriUDI(Lectori lector)
 {
     using (var context = new ModelContext())
     {
         context.Lectoris.Add(lector);
         foreach (var entry in context.ChangeTracker.Entries <BaseEntity>())
         {
             entry.State = EntityConvertState.ConvertState(entry.Entity.State);
             if (entry.State == EntityState.Modified)
             {
                 entry.State = EntityState.Unchanged;
                 var databaseValues = entry.GetDatabaseValues();
                 entry.OriginalValues.SetValues(databaseValues);
             }
         }
         context.SaveChanges();
     }
 }
Exemple #2
0
        public bool RegisterLector(Lectori lector)
        {
            using (var context = new ModelContext())
            {
                try
                {
                    Disciplina d;
                    try
                    {
                        d = context.Disciplinas.Single(s => s.NumeDisciplina == "Disciplina noua");
                        lector.DisciplinaIdDisciplina = d.IdDisciplina;
                    }
                    catch (Exception)
                    {
                        d = new Disciplina
                        {
                            NumeDisciplina = "Disciplina noua"
                        };

                        context.Disciplinas.Add(d);
                        context.SaveChanges();
                        d = context.Disciplinas.Single(s => s.NumeDisciplina == "Disciplina noua");

                        var list = context.Disciplinas;
                        foreach (var vv in list)
                        {
                            d = vv;
                            lector.DisciplinaIdDisciplina = d.IdDisciplina;
                            break;
                        }
                    }

                    LectoriUDI(lector);
                    return(true);
                }
                catch (Exception)
                {
                    return(false);
                }
            }
        }