public IHttpActionResult deleteone([FromUri] System.Int32 genreId
                                           )
        {
            LitGenreView result = db.LitGenreDbSet
                                  .Where(p => p.GenreId == genreId)
                                  .Select(itm => new LitGenreView()
            {
                GenreId   = itm.GenreId,
                GenreName = itm.GenreName
            }).FirstOrDefault();

            if (result == null)
            {
                return(NotFound());
            }

            LitGenre entityToDelete = db.LitGenreDbSet
                                      .Where(p => p.GenreId == result.GenreId)
                                      .FirstOrDefault();

            if (entityToDelete == null)
            {
                return(Ok(result));
            }
            db.LitGenreDbSet.Remove(entityToDelete);
            db.SaveChanges();
            return(Ok(result));
        }
        public IHttpActionResult addone([FromBody] LitGenreView viewToAdd)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            LitGenre entityToAdd = new LitGenre();

            entityToAdd.GenreId   = viewToAdd.GenreId;
            entityToAdd.GenreName = viewToAdd.GenreName;
            db.LitGenreDbSet.Add(entityToAdd);
            db.SaveChanges();

            LitGenreView result = db.LitGenreDbSet
                                  .Where(p => p.GenreId == entityToAdd.GenreId)
                                  .Select(itm => new LitGenreView()
            {
                GenreId   = itm.GenreId,
                GenreName = itm.GenreName
            }).FirstOrDefault();

            if (result == null)
            {
                return(NotFound());
            }
            return(Ok(result));
        }
        public IHttpActionResult updateone([FromBody] LitGenreView viewToUpdate)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            LitGenre resultEntity = db.LitGenreDbSet
                                    .Where(p => p.GenreId == viewToUpdate.GenreId)
                                    .FirstOrDefault();

            if (resultEntity == null)
            {
                return(NotFound());
            }

            resultEntity.GenreName       = viewToUpdate.GenreName;
            db.Entry(resultEntity).State = EntityState.Modified;
            db.SaveChanges();
            LitGenreView result = db.LitGenreDbSet
                                  .Where(p => p.GenreId == viewToUpdate.GenreId)
                                  .Select(itm => new LitGenreView()
            {
                GenreId   = itm.GenreId,
                GenreName = itm.GenreName
            }).FirstOrDefault();

            if (result == null)
            {
                return(NotFound());
            }
            return(Ok(result));
        }
Beispiel #4
0
 public static void InsertGenger(this LitDbContext db, int GenreId, string GenreName)
 {
     if (!db.LitGenreDbSet.Any(l => (l.GenreName == GenreName)))
     {
         LitGenre genre = new LitGenre()
         {
             GenreId   = GenreId,
             GenreName = GenreName
         };
         db.LitGenreDbSet.Add(genre);
         db.SaveChanges();
         db.Entry(genre).State = System.Data.Entity.EntityState.Detached;
     }
 }
Beispiel #5
0
        public static void PopulateAuthors(this LitDbContext db)
        {
            LitGenre   novel        = db.LitGenreDbSet.Where(l => (l.GenreName == "Literary novel")).FirstOrDefault();
            LitGenre   shortStory   = db.LitGenreDbSet.Where(l => (l.GenreName == "Literary short story")).FirstOrDefault();
            LitGenre   play         = db.LitGenreDbSet.Where(l => (l.GenreName == "Literary play")).FirstOrDefault();
            LitEdition firstEdition = db.LitEditionDbSet.Where(l => (l.EditionName == "First Edition")).FirstOrDefault();



            int MacmillanId = InsertPublisher(db, "Macmillan Inc.", "USA", "US");


            int authorId = InsertAuthor(db, "Jack", "London", new DateTime(1876, 1, 12), new DateTime(1916, 11, 22), "USA", "US");

            if (authorId > -1)
            {
                int ManuscriptId =
                    InsertManusript(db, "The Cruise of the Dazzler", new DateTime(1902, 2, 12), null, authorId, novel.GenreId, "en-US");
                InsertBook(db, "The Cruise of the Dazzler", new DateTime(1903, 2, 12), 1.2, MacmillanId, ManuscriptId, firstEdition.EditionId);

                ManuscriptId =
                    InsertManusript(db, "A Daughter of the Snows", new DateTime(1902, 3, 14), null, authorId, novel.GenreId, "en-US");
                InsertBook(db, "A Daughter of the Snows", new DateTime(1903, 2, 12), 1.3, MacmillanId, ManuscriptId, firstEdition.EditionId);

                ManuscriptId =
                    InsertManusript(db, "The Call of the Wild", new DateTime(1903, 4, 14), null, authorId, novel.GenreId, "en-US");
                InsertBook(db, "A Daughter of the Snows", new DateTime(1904, 4, 12), 1.3, MacmillanId, ManuscriptId, firstEdition.EditionId);

                ManuscriptId =
                    InsertManusript(db, "The Kempton-Wace Letters", new DateTime(1903, 4, 17), null, authorId, novel.GenreId, "en-US");
                InsertBook(db, "The Kempton-Wace Letters", new DateTime(1904, 4, 12), 1.4, MacmillanId, ManuscriptId, firstEdition.EditionId);

                ManuscriptId =
                    InsertManusript(db, "The Sea-Wolf", new DateTime(1904, 1, 17), null, authorId, novel.GenreId, "en-US");
                InsertBook(db, "The Sea-Wolf", new DateTime(1904, 4, 17), 1.5, MacmillanId, ManuscriptId, firstEdition.EditionId);

                ManuscriptId =
                    InsertManusript(db, "The Game", new DateTime(1905, 3, 12), null, authorId, novel.GenreId, "en-US");
                InsertBook(db, "The Game", new DateTime(1906, 3, 17), 1.5, MacmillanId, ManuscriptId, firstEdition.EditionId);


                ManuscriptId =
                    InsertManusript(db, "White Fang", new DateTime(1906, 4, 20), null, authorId, novel.GenreId, "en-US");
                InsertBook(db, "White Fang", new DateTime(1907, 4, 17), 1.5, MacmillanId, ManuscriptId, firstEdition.EditionId);

                ManuscriptId =
                    InsertManusript(db, "Before Adam", new DateTime(1907, 7, 28), null, authorId, novel.GenreId, "en-US");
                InsertBook(db, "Before Adam", new DateTime(1908, 4, 27), 1.6, MacmillanId, ManuscriptId, firstEdition.EditionId);

                ManuscriptId =
                    InsertManusript(db, "The Iron Heel", new DateTime(1908, 3, 27), null, authorId, novel.GenreId, "en-US");
                InsertBook(db, "The Iron Heel", new DateTime(1909, 5, 27), 1.7, MacmillanId, ManuscriptId, firstEdition.EditionId);

                ManuscriptId =
                    InsertManusript(db, "Martin Eden", new DateTime(1909, 4, 7), null, authorId, novel.GenreId, "en-US");
                InsertBook(db, "Martin Eden", new DateTime(1910, 5, 27), 1.7, MacmillanId, ManuscriptId, firstEdition.EditionId);



                ManuscriptId =
                    InsertManusript(db, "An Old Soldier's Story", new DateTime(1893, 1, 15), null, authorId, shortStory.GenreId, "en-US");
                InsertBook(db, "An Old Soldier's Story", new DateTime(1894, 2, 17), 1.7, MacmillanId, ManuscriptId, firstEdition.EditionId);

                ManuscriptId =
                    InsertManusript(db, "Who Believes in Ghosts!", new DateTime(1894, 2, 12), null, authorId, shortStory.GenreId, "en-US");
                InsertBook(db, "Who Believes in Ghosts!", new DateTime(1895, 5, 28), 1.7, MacmillanId, ManuscriptId, firstEdition.EditionId);

                ManuscriptId =
                    InsertManusript(db, "And 'FRISCO Kid Came Back", new DateTime(1894, 3, 11), null, authorId, shortStory.GenreId, "en-US");
                InsertBook(db, "And 'FRISCO Kid Came Back", new DateTime(1895, 4, 12), 1.7, MacmillanId, ManuscriptId, firstEdition.EditionId);

                ManuscriptId =
                    InsertManusript(db, "One More Unfortunate", new DateTime(1894, 4, 27), null, authorId, shortStory.GenreId, "en-US");
                InsertBook(db, "One More Unfortunate", new DateTime(1895, 4, 12), 1.7, MacmillanId, ManuscriptId, firstEdition.EditionId);

                ManuscriptId =
                    InsertManusript(db, "Night's Swim In Yeddo Bay", new DateTime(1894, 5, 17), null, authorId, shortStory.GenreId, "en-US");
                InsertBook(db, "Night's Swim In Yeddo Bay", new DateTime(1895, 4, 12), 1.7, MacmillanId, ManuscriptId, firstEdition.EditionId);

                ManuscriptId =
                    InsertManusript(db, "Sakaicho, Hona Asi And Hakadaki", new DateTime(1894, 6, 7), null, authorId, shortStory.GenreId, "en-US");
                InsertBook(db, "Sakaicho, Hona Asi And Hakadaki", new DateTime(1895, 4, 12), 1.7, MacmillanId, ManuscriptId, firstEdition.EditionId);

                ManuscriptId =
                    InsertManusript(db, "A Klondike Christmas", new DateTime(1896, 6, 16), null, authorId, shortStory.GenreId, "en-US");
                InsertBook(db, "A Klondike Christmas", new DateTime(1897, 4, 12), 1.7, MacmillanId, ManuscriptId, firstEdition.EditionId);

                ManuscriptId =
                    InsertManusript(db, "Mahatma's Little Joke", new DateTime(1896, 6, 26), null, authorId, shortStory.GenreId, "en-US");
                InsertBook(db, "Mahatma's Little Joke", new DateTime(1897, 4, 12), 1.7, MacmillanId, ManuscriptId, firstEdition.EditionId);



                ManuscriptId =
                    InsertManusript(db, "Theft", new DateTime(1909, 6, 26), null, authorId, play.GenreId, "en-US");
                InsertBook(db, "Theft", new DateTime(1910, 4, 12), 1.7, MacmillanId, ManuscriptId, firstEdition.EditionId);
                ManuscriptId =
                    InsertManusript(db, "Daughters of the Rich: A One Act Play", new DateTime(1914, 5, 26), null, authorId, play.GenreId, "en-US");
                InsertBook(db, "Daughters of the Rich: A One Act Play", new DateTime(1910, 4, 12), 1.7, MacmillanId, ManuscriptId, firstEdition.EditionId);
                ManuscriptId =
                    InsertManusript(db, "The Acorn Planter: A California Forest Play", new DateTime(1915, 5, 26), null, authorId, play.GenreId, "en-US");
                InsertBook(db, "The Acorn Planter: A California Forest Play", new DateTime(1910, 4, 12), 1.7, MacmillanId, ManuscriptId, firstEdition.EditionId);
            }


            int scribnerMagazineId = InsertPublisher(db, "Scribner's Magazine", "USA", "US");
            int scribnerSunId      = InsertPublisher(db, "Charles Scribner's Sons", "USA", "US");

            authorId = InsertAuthor(db, "Ernest", "Hemingway", new DateTime(1899, 7, 21), new DateTime(1961, 7, 2), "USA", "US");
            if (authorId > -1)
            {
                int ManuscriptId =
                    InsertManusript(db, "The Sun Also Rises", new DateTime(1925, 2, 12), null, authorId, novel.GenreId, "en-US");
                InsertBook(db, "The Sun Also Rises", new DateTime(1926, 2, 12), 1.2, scribnerMagazineId, ManuscriptId, firstEdition.EditionId);

                ManuscriptId =
                    InsertManusript(db, "A Farewell to Arms", new DateTime(1928, 2, 12), null, authorId, novel.GenreId, "en-US");
                InsertBook(db, "A Farewell to Arms", new DateTime(1929, 2, 12), 1.2, scribnerSunId, ManuscriptId, firstEdition.EditionId);

                ManuscriptId =
                    InsertManusript(db, "For Whom the Bell Tolls", new DateTime(1939, 2, 12), null, authorId, novel.GenreId, "en-US");
                InsertBook(db, "For Whom the Bell Tolls", new DateTime(1940, 2, 12), 1.2, scribnerSunId, ManuscriptId, firstEdition.EditionId);
                ManuscriptId =
                    InsertManusript(db, "The Old Man and the Sea", new DateTime(1951, 2, 12), null, authorId, novel.GenreId, "en-US");
                InsertBook(db, "The Old Man and the Sea", new DateTime(1952, 2, 12), 1.2, scribnerSunId, ManuscriptId, firstEdition.EditionId);
            }



            int wardLockId  = InsertPublisher(db, "Ward Lock & Co", "GBR", "GB");
            int stoughtonId = InsertPublisher(db, "Hodder & Stoughton", "GBR", "GB");

            authorId = InsertAuthor(db, "Arthur", "Conan Doyle", new DateTime(1859, 5, 22), new DateTime(1930, 7, 7), "GBR", "GB");
            {
                int ManuscriptId =                 // 20 November 1886
                                   InsertManusript(db, "The Mystery of Cloomber", new DateTime(1887, 2, 10), null, authorId, novel.GenreId, "en-GB");
                InsertBook(db, "The Mystery of Cloomber", new DateTime(1888, 11, 20), 1.2, wardLockId, ManuscriptId, firstEdition.EditionId);
                ManuscriptId =
                    InsertManusript(db, "Sherlock Holmes", new DateTime(1885, 2, 10), null, authorId, novel.GenreId, "en-GB");
                InsertBook(db, "Sherlock Holmes", new DateTime(1886, 11, 20), 1.2, wardLockId, ManuscriptId, firstEdition.EditionId);
                ManuscriptId =
                    InsertManusript(db, "The Lost World", new DateTime(1910, 2, 12), null, authorId, novel.GenreId, "en-GB");
                InsertBook(db, "The Lost World", new DateTime(1911, 2, 12), 1.2, stoughtonId, ManuscriptId, firstEdition.EditionId);
            }
        }