public string GenerateContent(List <Poet> poets, char alphabet)
        {
            var html = string.Empty;

            html += "<div class='total-poet'> " + alphabet.ToString().ToUpper() + " harfi ile başlayan <span class='total-poet-count'>" + poets.Count + "</span> şair bulundu </div>";

            html += "<table class=\'table table-hover\'>" +
                    "<thead>" +
                    " <tr>" +
                    " <th></th>" +
                    " <th>Adı Soyadı</th>" +
                    " <th style='width:25%'>Eser Sayısı</th>" + "" +
                    "</tr> " +
                    " </thead>" +
                    "<tbody>";

            for (int i = 0; i < poets.Count; i++)
            {
                Poet poet = poets[i];

                string link = $"/sayfalar/sair/{poet.PoetName.ReplaceForUrl()}.html";

                html += "<tr style='cursor:pointer'>" +
                        " <td>" + Convert.ToInt32(i + 1) + "</td>" +
                        " <td>" + poet.PoetName + "</td>" +
                        "<td><a href='" + link + "' <span class='total-poet-count'>" + poet.TotalPoem + " </span> Eser </a></td>" +
                        "</tr>";
            }

            html += " </tbody> </table>";

            return(html);
        }
Exemple #2
0
        private async Task <Poet> CurrentPoet()
        {
            var  userId = _caller.Claims.Single(c => c.Type == "id");
            Poet poet   = await _appDbContext.Poets.Include(c => c.Identity).SingleAsync(c => c.Identity.Id == userId.Value);

            return(poet);
        }
Exemple #3
0
        public void newPoet_checkId_shouldBeZero()
        {
            Poet f = new Poet
            {
            };

            Assert.That(f.Id, Is.EqualTo(0));
        }
Exemple #4
0
        public void createPoetDante_withVilaNouvaandSomeCharacters_shouldCreate()
        {
            Character dante = new Character
            {
                Name = "Dante"
            };
            Character beatrice = new Character
            {
                Name = "Beatrice"
            };
            Poem m = new Poem
            {
                Name = "Vila Nouva"
            };

            dante.Poem    = m;
            beatrice.Poem = m;
            m.Characters.Add(dante);
            m.Characters.Add(beatrice);
            Poet f = new Poet
            {
                Name = "Dante"
            };

            m.Author = f;
            f.Poems.Add(m);

            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);
                }
                using (session.BeginTransaction())
                {
                    var poets = session.CreateCriteria(typeof(Poet)).List <Poet>();
                    var poet  = poets[0];
                    Assert.That(poet.Poems[0].Name == "Vila Nouva");
                    Assert.That(poet.Poems[0].Characters.FirstOrDefault <Character>().Name == "Dante");

                    var people = session.CreateCriteria(typeof(Person)).List <Person>();
                    Assert.That(people.Count == 3);
                }
            }
        }
Exemple #5
0
        public static void Poem()
        {
            using (var db = new ShirenEntities())
            {
                var poem = new Poem {
                    Name = "赠汪伦"
                };
                var poet = new Poet {
                    Name = "李白"
                };
                var meter = new Meter {
                    TypeName = "赠友"
                };
                poem.Poet  = poet;
                poem.Meter = meter;
                db.Poem.Add(poem);

                poem = new Poem
                {
                    Name  = "登黄鹤楼",
                    Poet  = poet,
                    Meter = meter
                };
                db.Poem.Add(poem);


                poet = new Poet {
                    Name = "杜甫"
                };
                meter = new Meter {
                    TypeName = "抒情"
                };
                poem = new Poem
                {
                    Name  = "大漠孤烟直",
                    Poet  = poet,
                    Meter = meter
                };
                db.Poem.Add(poem);

                db.SaveChanges();
            }
            using (var db = new ShirenEntities())
            {
                var poems = db.Poem.ToList();
                poems.ForEach(a => Console.WriteLine($"诗名:{a.Name},诗人:{a.Poet.Name},类型:{a.Meter.TypeName}"));
            }
        }
Exemple #6
0
        public void createPoet_byDefault_shouldThrowException()
        {
            Poet f = new Poet
            {
            };

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

                    Assert.Throws <NHibernate.PropertyValueException>(() => session.SaveOrUpdate(f));
                }
            }
        }
Exemple #7
0
        public async Task <IActionResult> Post([FromBody] PoemViewModel poem)
        {
            Poet currentPoet = await CurrentPoet();

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            await _appDbContext.Poems.AddAsync(new Poem { Title         = poem.Title, Body = poem.Body,
                                                          PostToInspire = poem.PostToInspire, Poet = currentPoet });

            _appDbContext.SaveChanges();

            return(new OkObjectResult("Poem created"));
        }
Exemple #8
0
        public IHttpActionResult SavePoetImage()
        {
            var poetList = db.Poet.Where(p => p.image == null).Select(p => new { p.poetId, p.name }).ToList();

            for (int i = 0; i < poetList.Count(); i++)
            {
                string imageUrl = getPoetryImage(poetList[i].name, 1);
                Poet   poet     = new Poet();
                poet.poetId = poetList[i].poetId;
                poet.image  = imageUrl;
                DbEntityEntry <object> entry = db.Entry <object>(poet);
                entry.State = EntityState.Unchanged;
                entry.Property("image").IsModified = true;
                db.SaveChanges();
            }
            return(Json("suc"));
        }
Exemple #9
0
        public async Task <IActionResult> Update([FromBody] Poem poem)
        {
            Poet currentPoet = await CurrentPoet();

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            if (currentPoet.Id != poem.Poet.Id)
            {
                return(BadRequest("You can't update this poem"));
            }

            await _appDbContext.Poems.AddAsync(new Poem { Title         = poem.Title, Body = poem.Body,
                                                          PostToInspire = poem.PostToInspire, Poet = currentPoet });

            await _appDbContext.SaveChangesAsync();

            return(new OkObjectResult("Poem updated"));
        }
Exemple #10
0
        public static void Import_Poet(string name, string poem_name)
        {
            Poet poet = new Poet {
                Name = name
            };
            Poem poem = new Poem
            {
                Name   = poem_name,
                Author = poet
            };

            poet.Poems.Add(poem);

            ISession session1 = SQLiteSessionManager.GetCurrentSession();

            using (ITransaction transaction = session1.BeginTransaction())
            {
                session1.SaveOrUpdate(poet);

                transaction.Commit();
            }
        }
Exemple #11
0
        public static void build_politician()
        {
            var florence = DBHelper.GetAllWithRestrictionsEq <Place>("Name", "Florence")[0];

            var guido = new Poet
            {
                Name     = "Guido",
                FullName = "Guido Cavalcanti"
            };

            florence.AddPerson(guido);
            florence.AddPersonDead(guido);

            var cavalcanti10 = new Politician
            {
                Name     = "Cavalcante",
                FullName = "Cavalcante de' Cavalcanti"
            };

            cavalcanti10.AddChild(guido);

            var guido27 = new Politician
            {
                Name     = "Guido",
                FullName = "Guido Da Montefeltro"
            };
            ISession session1 = SQLiteSessionManager.GetCurrentSession();

            using (ITransaction transaction = session1.BeginTransaction())
            {
                session1.SaveOrUpdate(guido);
                session1.SaveOrUpdate(cavalcanti10);
                session1.SaveOrUpdate(guido27);
                transaction.Commit();
            }
        }
Exemple #12
0
        public void createPoetVirgil_withAeniedAndSomeCharacters_shouldCreate()
        {
            /*Person p1 = new Person
             * {
             *  Name = "Camilla"
             * };
             * Person p2 = new Person
             * {
             *  Name = "Nisus"
             * };
             * Person p3 = new Person
             * {
             *  Name = "Virgil"
             * };*/
            Character camilla = new Character
            {
                Name = "Camilla"
            };
            Character nisus = new Character
            {
                Name = "Nisus"
            };
            Poem m = new Poem
            {
                Name = "Aeneid"
            };

            camilla.Poem = m;
            nisus.Poem   = m;
            m.Characters.Add(camilla);
            m.Characters.Add(nisus);
            Poet f = new Poet
            {
                Name = "Virgil"
            };

            m.Author = f;
            f.Poems.Add(m);

            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);
                }
                using (session.BeginTransaction())
                {
                    var poets  = session.CreateCriteria(typeof(Poet)).List <Poet>();
                    var virgil = poets[0];
                    Assert.That(virgil.Poems[0].Name == "Aeneid");
                    Assert.That(virgil.Poems[0].Characters.FirstOrDefault <Character>().Name == "Camilla");


                    var people = session.CreateCriteria(typeof(Person)).List <Person>();
                    Assert.That(people.Count == 3);
                }
            }
        }
Exemple #13
0
        public void createPoetsVirgilandDante_SomeCharacters_shouldCreate()
        {
            Place fl = new Place
            {
                Name = "Florence"
            };
            Place mantuan = new Place
            {
                Name = "Mantuan"
            };

            Character camilla = new Character
            {
                Name = "Camilla"
            };
            Character nisus = new Character
            {
                Name = "Nisus"
            };
            Poem m = new Poem
            {
                Name = "Aeneid"
            };

            camilla.Poem = m;
            nisus.Poem   = m;
            m.Characters.Add(camilla);
            m.Characters.Add(nisus);
            Poet f = new Poet
            {
                Name      = "Virgil",
                BornPlace = mantuan
            };

            m.Author = f;
            f.Poems.Add(m);

            Character dante = new Character
            {
                Name      = "Dante",
                BornPlace = fl
            };
            Character beatrice = new Character
            {
                Name      = "Beatrice",
                BornPlace = fl
            };
            Poem m2 = new Poem
            {
                Name = "Vila Nouva"
            };

            dante.Poem    = m2;
            beatrice.Poem = m2;
            m2.Characters.Add(dante);
            m2.Characters.Add(beatrice);
            Poet f2 = new Poet
            {
                Name      = "Dante",
                BornPlace = fl
            };

            m2.Author = f2;
            f2.Poems.Add(m2);

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

                    session.SaveOrUpdate(f);
                    session.SaveOrUpdate(f2);
                    transaction.Commit();

                    Assert.That(f.Id > 0);
                    Assert.That(f2.Id > 0);
                }

                using (session.BeginTransaction())
                {
                    var poets  = session.CreateCriteria(typeof(Poet)).List <Poet>();
                    var virgil = poets[0];
                    Assert.That(virgil.Poems[0].Name == "Aeneid");
                    Assert.That(virgil.Poems[0].Characters.FirstOrDefault <Character>().Name == "Camilla");

                    var dante_poet = poets[1];
                    Assert.That(dante_poet.Poems[0].Name == "Vila Nouva");
                    Assert.That(dante_poet.Poems[0].Characters.FirstOrDefault <Character>().Name == "Dante");

                    var people = session.CreateCriteria(typeof(Person)).List <Person>();
                    Assert.That(people.Count == 6);

                    var sites = session.CreateCriteria(typeof(Place)).List <Place>();
                    Assert.That(sites.Count == 2);
                }
            }
        }
Exemple #14
0
        private void button1_Click(object sender, EventArgs e)
        {
            var name     = textBoxName.Text;
            var bookName = "Inferno";

            if (textBoxBook.Text == "2")
            {
                bookName = "Purgatorio";
            }
            if (textBoxBook.Text == "3")
            {
                bookName = "Paridiso";
            }
            Note note = new Note
            {
                Name       = name,
                Commentary = textBoxCommentary.Text
            };

            note.Loc = new Loc
            {
                Book  = bookName,
                Canto = int.Parse(textBoxCanto.Text),
                Start = int.Parse(textBoxStart.Text),
                End   = int.Parse(textBoxEnd.Text),
            };
            if (checkBoxTerm.Checked == true)
            {
                var terms = _dBUtilTerm.GetAllWithOrRestrictionsStringInsentiveLike("Name", name, "Alias");
                if (terms == null || terms.Count == 0)
                {
                    var itemType = (string)comboBoxTermItemType.SelectedItem;
                    var term     = new Term
                    {
                        Name = name
                    };
                    if (!string.IsNullOrEmpty(itemType))
                    {
                        if (itemType == "Item")
                        {
                            itemType = "Metaphor";
                        }
                        ;
                        term.SetMetaphorItem(itemType, "");

                        switch (itemType)
                        {
                        case "Place":
                        {
                            var placeUtil = new DBUtil <Place>();
                            var places    = placeUtil.GetAllWithOrRestrictionsStringInsentiveLike("Name", name, "Alias");
                            if (places == null || places.Count == 0)
                            {
                                var place = new Place
                                {
                                    Name = name
                                };
                                placeUtil.save(place);
                            }
                        }
                        break;

                        case "Politician":
                        {
                            var placeUtil = new DBUtil <Politician>();
                            var places    = placeUtil.GetAllWithOrRestrictionsStringInsentiveLike("Name", name, "Alias");
                            if (places == null || places.Count == 0)
                            {
                                var place = new Politician
                                {
                                    Name = name
                                };
                                placeUtil.save(place);
                            }
                        }
                        break;

                        case "Poet":
                        {
                            var placeUtil = new DBUtil <Poet>();
                            var places    = placeUtil.GetAllWithOrRestrictionsStringInsentiveLike("Name", name, "Alias");
                            if (places == null || places.Count == 0)
                            {
                                var place = new Poet
                                {
                                    Name = name
                                };
                                placeUtil.save(place);
                            }
                        }
                        break;

                        case "Character":
                        {
                            var placeUtil = new DBUtil <Character>();
                            var places    = placeUtil.GetAllWithOrRestrictionsStringInsentiveLike("Name", name, "Alias");
                            if (places == null || places.Count == 0)
                            {
                                var place = new Character
                                {
                                    Name = name
                                };
                                placeUtil.save(place);
                            }
                        }
                        break;

                        case "Person":
                        {
                            var personUtil = new DBUtil <Person>();
                            var people     = personUtil.GetAllWithOrRestrictionsStringInsentiveLike("Name", name, "Alias");
                            if (people == null || people.Count == 0)
                            {
                                var person = new Person
                                {
                                    Name = name
                                };
                                personUtil.save(person);
                            }
                        }
                        break;
                        }
                    }
                    term.AddNote(note);
                    _dBUtilTerm.save(term);
                }
                else
                {
                    var term = terms[0];
                    term.AddNote(note);
                    _dBUtilTerm.save(term);
                }
            }
            _dBUtilNote.save(note);
        }
Exemple #15
0
        public static void build_poets_elite_six()
        {
            string poet_str  = "Dante,          Virgil,      Homer,   Horace,        Ovid,          Lucan";
            string born_str  = "Florence,      Mantua,   Venusia,    Sumona,            ,               ";
            string dead_str  = "Ravenna,              ,      Rome,          ,        Rome,               ";
            string write_str = "Divine Comedy,  Aeneid,     Iliad,          , The Metamorphoses, Pharsalia";

            string[] arr_poets   = poet_str.Split(',');
            string[] arr_born    = born_str.Split(',');
            string[] arr_dead    = dead_str.Split(',');
            string[] arr_writing = write_str.Split(',');
            ISession session1    = SQLiteSessionManager.GetCurrentSession();

            using (ITransaction transaction = session1.BeginTransaction())
            {
                int ind = 0;
                for (int i = 0; i < arr_poets.Length; i++)
                {
                    if (string.IsNullOrEmpty(arr_poets[i]))
                    {
                        continue;
                    }

                    var   str_born = arr_born[i].Trim(new char[] { ' ' });
                    var   str_dead = arr_dead[i].Trim(new char[] { ' ' });
                    Place pl_born;
                    Place pl_dead;
                    if (string.IsNullOrEmpty(str_born))
                    {
                        pl_born = null;
                    }
                    else
                    {
                        var places = DBHelper.GetAllWithRestrictionsEq <Place>("Name", str_born);
                        if (places != null)
                        {
                            pl_born = places[0];
                        }
                        else
                        {
                            pl_born = new Place
                            {
                                Name = str_born
                            };
                        }
                    }
                    if (string.IsNullOrEmpty(str_dead))
                    {
                        pl_dead = null;
                    }
                    else
                    {
                        var places = DBHelper.GetAllWithRestrictionsEq <Place>("Name", str_dead);
                        if (places != null)
                        {
                            pl_dead = places[0];
                        }
                        else
                        {
                            pl_dead = new Place
                            {
                                Name = str_dead
                            };
                        }
                    }

                    var objPoet = new Poet
                    {
                        Name = arr_poets[i].Trim(new char[] { ',', ' ' }),
                    };
                    if (pl_born != null)
                    {
                        pl_born.AddPerson(objPoet);
                    }
                    if (pl_dead != null)
                    {
                        pl_dead.AddPersonDead(objPoet);
                    }
                    var poem_name = arr_writing[i].Trim(new char[] { ',', ' ' });
                    if (!string.IsNullOrEmpty(poem_name))
                    {
                        var poem = new Poem
                        {
                            Name = poem_name
                        };
                        objPoet.AddPoem(poem);
                        session1.SaveOrUpdate(poem);
                    }

                    session1.SaveOrUpdate(objPoet);

                    if (pl_born != null)
                    {
                        session1.SaveOrUpdate(pl_born);
                    }
                    if (pl_dead != null)
                    {
                        session1.SaveOrUpdate(pl_dead);
                    }
                }


                transaction.Commit();
            }
        }