public IHttpActionResult updateone([FromBody] LitLanguageView viewToUpdate)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            LitLanguage resultEntity = db.LitLanguageDbSet
                                       .Where(p => p.Iso3 == viewToUpdate.Iso3)
                                       .Where(p => p.Iso2 == viewToUpdate.Iso2)
                                       .FirstOrDefault();

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

            resultEntity.LanguageName    = viewToUpdate.LanguageName;
            db.Entry(resultEntity).State = EntityState.Modified;
            db.SaveChanges();
            LitLanguageView result = db.LitLanguageDbSet
                                     .Where(p => p.Iso3 == viewToUpdate.Iso3)
                                     .Where(p => p.Iso2 == viewToUpdate.Iso2)
                                     .Select(itm => new LitLanguageView()
            {
                Iso3         = itm.Iso3,
                Iso2         = itm.Iso2,
                LanguageName = itm.LanguageName
            }).FirstOrDefault();

            if (result == null)
            {
                return(NotFound());
            }
            return(Ok(result));
        }
        public IHttpActionResult updateone([FromBody] LitEditionView viewToUpdate)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            LitEdition resultEntity = db.LitEditionDbSet
                                      .Where(p => p.EditionId == viewToUpdate.editionId)
                                      .FirstOrDefault();

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

            resultEntity.EditionName     = viewToUpdate.editionName;
            db.Entry(resultEntity).State = EntityState.Modified;
            db.SaveChanges();
            LitEditionView result = db.LitEditionDbSet
                                    .Where(p => p.EditionId == viewToUpdate.editionId)
                                    .Select(itm => new LitEditionView()
            {
                editionId   = itm.EditionId,
                editionName = itm.EditionName
            }).FirstOrDefault();

            if (result == null)
            {
                return(NotFound());
            }
            return(Ok(result));
        }
Пример #3
0
        public static int InsertBook(this LitDbContext db, string BookTitle, DateTime PublicationDate, Double Price, int PublisherIdRef, int ManuscriptIdRef, int?EditionIdRef)
        {
            int     result = -1;
            LitBook book   = db.LitBookDbSet.Where(a => (a.BookTitle == BookTitle) && (a.PublisherIdRef == PublisherIdRef) && (a.ManuscriptIdRef == ManuscriptIdRef)).FirstOrDefault();

            if (book != null)
            {
                result = book.BookId;
                db.Entry(book).State = System.Data.Entity.EntityState.Detached;
                return(result);
            }
            book = new LitBook()
            {
                BookTitle       = BookTitle,
                PublicationDate = PublicationDate,
                Price           = Price,
                PublisherIdRef  = PublisherIdRef,
                ManuscriptIdRef = ManuscriptIdRef,
                EditionIdRef    = EditionIdRef
            };
            db.LitBookDbSet.Add(book);
            db.SaveChanges();
            result = book.BookId;
            db.Entry(book).State = System.Data.Entity.EntityState.Detached;
            return(result);
        }
Пример #4
0
        public static int InsertManusript(this LitDbContext db, string ManuscriptTitle, DateTime CompletionDate, DateTime?BeginningDate, int AuthorIdRef, int GenreIdRef, string DialectIdRef)
        {
            int           result     = -1;
            LitManuscript manuscript = db.LitManuscriptDbSet.Where(a => (a.ManuscriptTitle == ManuscriptTitle) && (a.AuthorIdRef == AuthorIdRef)).FirstOrDefault();

            if (manuscript != null)
            {
                result = manuscript.ManuscriptId;
                db.Entry(manuscript).State = System.Data.Entity.EntityState.Detached;
                return(result);
            }
            manuscript = new LitManuscript()
            {
                ManuscriptTitle = ManuscriptTitle,
                CompletionDate  = CompletionDate,
                BeginningDate   = BeginningDate,
                AuthorIdRef     = AuthorIdRef,
                GenreIdRef      = GenreIdRef,
                DialectIdRef    = DialectIdRef
            };
            db.LitManuscriptDbSet.Add(manuscript);
            db.SaveChanges();
            result = manuscript.ManuscriptId;
            db.Entry(manuscript).State = System.Data.Entity.EntityState.Detached;
            return(result);
        }
Пример #5
0
        public static int InsertAuthor(this LitDbContext db, string FirstName, string LastName, DateTime BirthDate, DateTime DeathDate, string Iso3CntrRef, string Iso2CntrRef)
        {
            int       result = -1;
            LitAuthor author = db.LitAuthorDbSet.Where(a => (a.FirstName == FirstName) && (a.LastName == LastName)).FirstOrDefault();

            if (author != null)
            {
                result = author.AuthorId;
                db.Entry(author).State = System.Data.Entity.EntityState.Detached;
                return(result);
            }
            author = new LitAuthor()
            {
                FirstName   = FirstName,
                LastName    = LastName,
                BirthDate   = BirthDate,
                DeathDate   = DeathDate,
                Iso3CntrRef = Iso3CntrRef,
                Iso2CntrRef = Iso2CntrRef
            };
            db.LitAuthorDbSet.Add(author);
            db.SaveChanges();
            result = author.AuthorId;
            db.Entry(author).State = System.Data.Entity.EntityState.Detached;
            return(result);
        }
Пример #6
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;
     }
 }
Пример #7
0
 public static void InsertEdition(this LitDbContext db, int EditionId, string EditionName)
 {
     if (!db.LitEditionDbSet.Any(l => (l.EditionName == EditionName)))
     {
         LitEdition edition = new LitEdition()
         {
             EditionId   = EditionId,
             EditionName = EditionName
         };
         db.LitEditionDbSet.Add(edition);
         db.SaveChanges();
         db.Entry(edition).State = System.Data.Entity.EntityState.Detached;
     }
 }
Пример #8
0
        public static void PopulateDialects(this LitDbContext db)
        {
            CultureInfo[] cultureInfos = CultureInfo.GetCultures(CultureTypes.AllCultures & CultureTypes.SpecificCultures);
            foreach (CultureInfo cultureInfo in cultureInfos)
            {
                if (string.IsNullOrEmpty(cultureInfo.Name))
                {
                    continue;
                }
                RegionInfo regionInfo = new RegionInfo(cultureInfo.Name);

                if (!db.LitLanguageDbSet.Any(l => (l.Iso3 == cultureInfo.ThreeLetterISOLanguageName) && (l.Iso2 == cultureInfo.TwoLetterISOLanguageName)))
                {
                    continue;
                }
                if (!db.LitCountryDbSet.Any(c => (c.Iso3 == regionInfo.ThreeLetterISORegionName) && (c.Iso2 == regionInfo.TwoLetterISORegionName)))
                {
                    continue;
                }
                if (db.LitDialectDbSet.Any(d => d.DialectId == cultureInfo.Name))
                {
                    continue;
                }
                if (!db.LitDialectDbSet.Any(d =>
                                            (d.Iso3CntrRef == regionInfo.ThreeLetterISORegionName) && (d.Iso2CntrRef == regionInfo.TwoLetterISORegionName) &&
                                            (d.Iso3LngRef == cultureInfo.ThreeLetterISOLanguageName) && (d.Iso2LngRef == cultureInfo.TwoLetterISOLanguageName)))
                {
                    LitDialect dialect = new LitDialect()
                    {
                        DialectId = cultureInfo.Name,

                        Iso3CntrRef = regionInfo.ThreeLetterISORegionName,
                        Iso2CntrRef = regionInfo.TwoLetterISORegionName,

                        Iso3LngRef = cultureInfo.ThreeLetterISOLanguageName,
                        Iso2LngRef = cultureInfo.TwoLetterISOLanguageName,

                        DialectName = cultureInfo.EnglishName
                    };
                    db.LitDialectDbSet.Add(dialect);
                    db.SaveChanges();
                    db.Entry(dialect).State = System.Data.Entity.EntityState.Detached;
                }
            }
        }
Пример #9
0
        public static int InsertPublisher(this LitDbContext db, string PublisherName, string Iso3CntrRef, string Iso2CntrRef)
        {
            int          result    = -1;
            LitPublisher publisher = db.LitPublisherDbSet.Where(a => (a.PublisherName == PublisherName) && (a.Iso3CntrRef == Iso3CntrRef)).FirstOrDefault();

            if (publisher != null)
            {
                result = publisher.PublisherId;
                db.Entry(publisher).State = System.Data.Entity.EntityState.Detached;
                return(result);
            }
            publisher = new LitPublisher()
            {
                PublisherName = PublisherName,
                Iso3CntrRef   = Iso3CntrRef,
                Iso2CntrRef   = Iso2CntrRef
            };
            db.LitPublisherDbSet.Add(publisher);
            db.SaveChanges();
            result = publisher.PublisherId;
            db.Entry(publisher).State = System.Data.Entity.EntityState.Detached;
            return(result);
        }
Пример #10
0
        public static void PopulateLanguages(this LitDbContext db)
        {
            CultureInfo[] cultureInfos = CultureInfo.GetCultures(CultureTypes.NeutralCultures);
            foreach (CultureInfo cultureInfo in cultureInfos)
            {
                if (string.IsNullOrEmpty(cultureInfo.Name))
                {
                    continue;
                }
                if (!db.LitLanguageDbSet.Any(l => (l.Iso3 == cultureInfo.ThreeLetterISOLanguageName) && (l.Iso2 == cultureInfo.TwoLetterISOLanguageName)))
                {
                    LitLanguage lang = new LitLanguage()
                    {
                        Iso3         = cultureInfo.ThreeLetterISOLanguageName,
                        Iso2         = cultureInfo.TwoLetterISOLanguageName,
                        LanguageName = cultureInfo.EnglishName
                    };
                    db.LitLanguageDbSet.Add(lang);

                    db.SaveChanges();
                    db.Entry(lang).State = System.Data.Entity.EntityState.Detached;
                }
            }
        }
Пример #11
0
 public static void PopulateCounties(this LitDbContext db)
 {
     CultureInfo[] cultureInfos = CultureInfo.GetCultures(CultureTypes.AllCultures & CultureTypes.SpecificCultures);
     foreach (CultureInfo cultureInfo in cultureInfos)
     {
         if (string.IsNullOrEmpty(cultureInfo.Name))
         {
             continue;
         }
         RegionInfo regionInfo = new RegionInfo(cultureInfo.Name);
         if (!db.LitCountryDbSet.Any(c => (c.Iso3 == regionInfo.ThreeLetterISORegionName) && (c.Iso2 == regionInfo.TwoLetterISORegionName)))
         {
             LitCountry сountry = new LitCountry()
             {
                 Iso3        = regionInfo.ThreeLetterISORegionName,
                 Iso2        = regionInfo.TwoLetterISORegionName,
                 CountryName = regionInfo.EnglishName
             };
             db.LitCountryDbSet.Add(сountry);
             db.SaveChanges();
             db.Entry(сountry).State = System.Data.Entity.EntityState.Detached;
         }
     }
 }