public static bool Eliminar(int id)
        {
            bool eliminado = false;

            Contexto contexto = new Contexto();

            try
            {
                Canto canto = contexto.cantos.Find(id);
                contexto.cantos.Remove(canto);
                if (contexto.SaveChanges() > 0)
                {
                    eliminado = true;
                }

                contexto.Dispose();
            }

            catch (Exception)
            {
                throw;
            }

            return(eliminado);
        }
        public void createCanto_withGivenLine_shouldCreate()
        {
            Line line = new Line
            {
                Number = 1,
                Text   = "In the middle of life"
            };
            Canto f = new Canto
            {
            };

            f.AddLine(line);

            using (ISession session = sqliteSessionFactory.Session)
            {
                using (ITransaction transaction = session.BeginTransaction())
                {
                    Assert.That(f.Id == 0);

                    session.SaveOrUpdate(f);

                    transaction.Commit();

                    Assert.That(f.Id > 0);
                }
            }
        }
Beispiel #3
0
        private void BuscarButton_Click(object sender, EventArgs e)
        {
            errorProvider.Clear();

            if (Validar(1))
            {
                MessageBox.Show("Ingrese un ID");
                return;
            }

            int   id    = Convert.ToInt32(CantoNumericUpDown.Value);
            Canto canto = BLL.CantoBLL.Buscar(id);

            if (canto != null)
            {
                NombreTextBox.Text           = canto.Nombre;
                VersiculoTextBox.Text        = canto.Versiculo;
                ColorComboBox.SelectedText   = canto.Color;
                MomentoComboBox.SelectedText = canto.Momento;
                TiempoComboBox.SelectedText  = canto.Tiempo;
                PaginaNumericUpDown.Value    = canto.pagina;
            }
            else
            {
                MessageBox.Show("No se encontro", "Fallo", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Beispiel #4
0
        public void createBook_withFirst3LinesOfInferno_shouldCreate()
        {
            Line line1 = new Line
            {
                Number = 1,
                Text   = "Halfway along our journey to life's end"
            };
            Line line2 = new Line
            {
                Number = 2,
                Text   = "I found myself astray in a darkwood,"
            };
            Line line3 = new Line
            {
                Number = 3,
                Text   = "Since the rightway was no where to be found."
            };
            Canto canto1 = new Canto
            {
                Number = 1
            };

            canto1.AddLine(line1);
            canto1.AddLine(line2);
            canto1.AddLine(line3);

            Book inferno = new Book
            {
                Number = 1,
                Name   = "Inferno"
            };

            inferno.AddCanto(canto1);


            using (ISession session = sqliteSessionFactory.Session)
            {
                using (ITransaction transaction = session.BeginTransaction())
                {
                    Assert.That(inferno.Id == 0);

                    session.SaveOrUpdate(inferno);

                    transaction.Commit();

                    Assert.That(inferno.Id > 0);
                }

                using (session.BeginTransaction())
                {
                    var resbooks  = session.CreateCriteria(typeof(Book)).List <Book>();
                    var resbook   = resbooks[0];
                    var rescantos = resbooks[0].Cantos;
                    var text      = rescantos[0].ToString();
                    Assert.That(resbook.Name == "Inferno");
                    Assert.That(text.StartsWith("Halfway"));
                }
            }
        }
Beispiel #5
0
        public static void Import_Book(string name, int number, string text0)
        {
            Book book = new Book
            {
                Number = number,
                Name   = name,
            };
            Canto canto = new Canto {
            };


            using (var reader = new StringReader(text0))
            {
                string txtline     = string.Empty;
                var    cantoNumber = 1;
                int    lineNumber  = 1;
                do
                {
                    txtline = reader.ReadLine();
                    if (txtline == null)
                    {
                        break;
                    }
                    txtline = txtline.Replace("\t", "").Trim(' ');
                    if (!string.IsNullOrEmpty(txtline))
                    {
                        if (txtline.StartsWith("##"))
                        {
                            cantoNumber = int.Parse(Regex.Replace(txtline, "## (.*)", "$1", RegexOptions.IgnoreCase));
                            lineNumber  = 1;
                            canto       = new Canto
                            {
                                Number = cantoNumber
                            };
                            book.AddCanto(canto);
                        }
                        else
                        {
                            var line = new Line
                            {
                                Number = lineNumber,
                                Text   = txtline
                            };
                            canto.AddLine(line);
                            lineNumber++;
                        }
                    }
                }while (txtline != null);
            }

            ISession session1 = SQLiteSessionManager.GetCurrentSession();

            using (ITransaction transaction = session1.BeginTransaction())
            {
                session1.Save(book);

                transaction.Commit();
            }
        }
Beispiel #6
0
        private Canto LlenaClase()
        {
            Canto canto = new Canto();

            canto.CantoId   = Convert.ToInt32(CantoNumericUpDown.Value);
            canto.Nombre    = NombreTextBox.Text;
            canto.Versiculo = VersiculoTextBox.Text;
            canto.pagina    = Convert.ToInt32(PaginaNumericUpDown.Value);
            canto.Color     = ColorComboBox.Text;
            canto.Momento   = MomentoComboBox.Text;
            canto.Tiempo    = TiempoComboBox.Text;

            return(canto);
        }
Beispiel #7
0
        private Canto Vaciar()
        {
            Canto canto = new Canto();

            CantoNumericUpDown.Value = 0;
            NombreTextBox.Clear();
            VersiculoTextBox.Clear();
            PaginaNumericUpDown.Value     = 0;
            ColorComboBox.SelectedIndex   = -1;
            MomentoComboBox.SelectedIndex = -1;
            TiempoComboBox.SelectedIndex  = -1;

            return(canto);
        }
        public static Canto Buscar(int id)
        {
            Canto    canto    = new Canto();
            Contexto contexto = new Contexto();

            try
            {
                canto = contexto.cantos.Find(id);
                contexto.Dispose();
            }

            catch (Exception)
            {
                throw;
            }

            return(canto);
        }
        public void createCanto_byDefault_shouldCreate()
        {
            Canto f = new Canto
            {
            };

            using (ISession session = sqliteSessionFactory.Session)
            {
                using (ITransaction transaction = session.BeginTransaction())
                {
                    Assert.That(f.Id == 0);

                    session.SaveOrUpdate(f);

                    transaction.Commit();

                    Assert.That(f.Id > 0);
                }
            }
        }
        public static bool Guardar(Canto canto)
        {
            bool     guardado = false;
            Contexto contexto = new Contexto();

            try
            {
                if (contexto.cantos.Add(canto) != null)
                {
                    contexto.SaveChanges();
                    guardado = true;
                }

                contexto.Dispose();
            }
            catch (Exception)
            {
                throw;
            }
            return(guardado);
        }
        public static bool Modificar(Canto canto)
        {
            bool modificado = false;

            Contexto contexto = new Contexto();

            try
            {
                contexto.Entry(canto).State = EntityState.Modified;
                if (contexto.SaveChanges() > 0)
                {
                    modificado = true;
                }

                contexto.Dispose();
            }

            catch (Exception)
            {
                throw;
            }

            return(modificado);
        }
Beispiel #12
0
        public void createNote_fromTheFirst3LinesOfInferno()
        {
            Line line1 = new Line
            {
                Number = 1,
                Text   = "Halfway along our journey to life's end"
            };
            Line line2 = new Line
            {
                Number = 2,
                Text   = "I found myself astray in a dark wood,"
            };
            Line line3 = new Line
            {
                Number = 3,
                Text   = "Since the rightway was no where to be found."
            };
            Line line4 = new Line
            {
                Number = 4,
                Text   = "How hard a thing it is to express the horr"
            };
            Line line5 = new Line
            {
                Number = 5,
                Text   = "of that wild wood, so difficult, so dense"
            };
            Line line6 = new Line
            {
                Number = 6,
                Text   = "Even to think of it renews my terror."
            };
            Canto canto1 = new Canto
            {
                Number = 1
            };

            canto1.AddLine(line1);
            canto1.AddLine(line2);
            canto1.AddLine(line3);
            canto1.AddLine(line4);
            canto1.AddLine(line5);
            canto1.AddLine(line6);

            Book inferno = new Book
            {
                Number = 1,
                Name   = "Inferno"
            };

            inferno.AddCanto(canto1);

            Note note = new Note
            {
                Commentary = "Life span is 70 years, at the midpoint is 1300 CE, Dante was 35 years old."
            };

            note.Loc = new Loc
            {
                Book  = "Inferno",
                Canto = 1,
                Start = 1
            };

            using (ISession session = sqliteSessionFactory.Session)
            {
                using (ITransaction transaction = session.BeginTransaction())
                {
                    Assert.That(note.Id == 0);
                    session.SaveOrUpdate(inferno);
                    session.SaveOrUpdate(note);

                    transaction.Commit();

                    Assert.That(note.Id > 0);
                }

                using (session.BeginTransaction())
                {
                    var resnotes = session.CreateCriteria(typeof(Note)).List <Note>();
                    var resnote  = resnotes[0];

                    var resCanto = session.CreateCriteria(typeof(Canto))
                                   .CreateCriteria("Book")
                                   .Add(Restrictions.Eq("Id", 1))
                                   .List <Canto>();
                    var resCanto2 = session.CreateCriteria(typeof(Canto))
                                    .CreateCriteria("Book")
                                    .Add(Restrictions.InsensitiveLike("Name", "Inferno"))
                                    .List <Canto>();

                    var search = session.CreateCriteria(typeof(Line))
                                 .Add(Restrictions.Eq("Number", 2))
                                 .CreateCriteria("Canto")
                                 .CreateCriteria("Book")
                                 .Add(Restrictions.InsensitiveLike("Name", "Inferno"))
                                 .Add(Restrictions.Eq("Number", 1))

                                 .List <Line>();
                    Assert.That(search[0].Text.Contains("wood") == true);
                }
            }
        }
Beispiel #13
0
        public void init()
        {
            sqliteSessionFactory = new InMemorySqLiteSessionFactory();


            Line line1 = new Line
            {
                Number = 1,
                Text   = "Halfway along our journey to life's end"
            };
            Line line2 = new Line
            {
                Number = 2,
                Text   = "I found myself astray in a dark wood,"
            };
            Line line3 = new Line
            {
                Number = 3,
                Text   = "Since the rightway was no where to be found."
            };
            Line line4 = new Line
            {
                Number = 4,
                Text   = "How hard a thing it is to express the horr"
            };
            Line line5 = new Line
            {
                Number = 5,
                Text   = "of that wild wood, so difficult, so dense"
            };
            Line line6 = new Line
            {
                Number = 6,
                Text   = "Even to think of it renews my terror."
            };
            Canto canto1 = new Canto
            {
                Number = 1
            };

            canto1.AddLine(line1);
            canto1.AddLine(line2);
            canto1.AddLine(line3);
            canto1.AddLine(line4);
            canto1.AddLine(line5);
            canto1.AddLine(line6);

            Book inferno = new Book
            {
                Number = 1,
                Name   = "Inferno"
            };

            inferno.AddCanto(canto1);

            Note note = new Note
            {
                Loc = new Loc
                {
                    Book  = "Inferno",
                    Canto = 1,
                    Start = 2,
                    End   = 2
                }
            };

            Term wildness = new Term
            {
                Name  = "wood",
                Alias = "forest,wildness"
            };

            wildness.AddNote(note);
            wildness.SetMetaphorItem("metaphor", "");

            session = sqliteSessionFactory.Session;
            {
                using (ITransaction transaction = session.BeginTransaction())
                {
                    Assert.That(note.Id == 0);
                    session.SaveOrUpdate(inferno);
                    session.SaveOrUpdate(note);
                    session.SaveOrUpdate(wildness);

                    transaction.Commit();
                }
            }
        }