internal int deleteEntry(int ID) { rulesencyclopediaDBEntities1 context = null; var result = -999999; try { context = new rulesencyclopediaDBEntities1(); { var entry = new Entry { Id = ID }; context.Entry.Attach(entry); context.Entry.Remove(entry); result = context.SaveChanges(); } } catch (EntityException ex) { exHandler.exceptionHandlerEntity(ex, "Something went wrong while deleting the user"); } finally { context.Dispose(); } return(result); }
internal GameDTO getGame(int ID) { Game game = null; GameDTO gameDTO = null; rulesencyclopediaDBEntities1 context = null; try { context = new rulesencyclopediaDBEntities1(); { game = context.Game.Single(element => element.Id == ID); gameDTO = (GameDTO)DTOConverter.Converter(new GameDTO(), game); } } catch (EntityException ex) { exHandler.exceptionHandlerEntity(ex, "something went wrong when getting game"); } catch (System.InvalidOperationException ex) { exHandler.exceptionHandlerInvalidOperation(ex, "Something went wrong. Record not found."); } finally { context.Dispose(); } return(gameDTO); }
internal int postEntry(Entry entry) { rulesencyclopediaDBEntities1 context = null; int result = -999999; try { context = new rulesencyclopediaDBEntities1(); { //getting back the key for the created user. context.Entry.Add(entry); result = context.SaveChanges(); return(result); } } catch (EntityException ex) { exHandler.exceptionHandlerEntity(ex, "Something went wrong when creating new game"); } finally { context.Dispose(); } return(result); }
internal List <EntryDTO> getEntriesForToc(int TOCId) { List <Entry> entryList = null; rulesencyclopediaDBEntities1 context = null; EntryDTO entryDTO = null; List <EntryDTO> entryDTOs = null; try { context = new rulesencyclopediaDBEntities1(); { entryList = context.Entry.Where(element => element.TOC == TOCId).OrderBy(element => element.ParagraphNumber).ToList(); entryDTOs = new List <EntryDTO>(); foreach (Entry entry in entryList) { entryDTO = (EntryDTO)DTOConverter.Converter(new EntryDTO(), entry); entryDTOs.Add(entryDTO); } } } catch (EntityException ex) { exHandler.exceptionHandlerEntity(ex, "something happened while fetching the entryList"); } finally { context.Dispose(); } return(entryDTOs); }
internal int deleteGame(int ID) { rulesencyclopediaDBEntities1 context = null; Game game = null; try { context = new rulesencyclopediaDBEntities1(); { game = new Game { Id = ID }; context.Game.Attach(game); context.Game.Remove(game); context.SaveChanges(); } } catch (EntityException ex) { exHandler.exceptionHandlerEntity(ex, "Something went wrong while deleting the user"); } finally { context.Dispose(); } return(game.Id); }
internal List <GameDTO> getGameList() { List <Game> gameList = null; List <GameDTO> gameDTOs = null; rulesencyclopediaDBEntities1 context = null; try { context = new rulesencyclopediaDBEntities1(); { //Getting the games list from DB gameList = context.Game.ToList(); gameDTOs = new List <GameDTO>(); foreach (Game game in gameList) { GameDTO gameDTO = (GameDTO)DTOConverter.Converter(new GameDTO(), game); gameDTOs.Add(gameDTO); } } } catch (EntityException ex) { exHandler.exceptionHandlerEntity(ex, "something happened while fetching the gamelist"); } finally { context.Dispose(); } return(gameDTOs); }
internal List <TOCDTO> getTOCList(int gameID) { List <TOC> TOCList = null; List <TOCDTO> tocDTOs = null; rulesencyclopediaDBEntities1 context = null; try { context = new rulesencyclopediaDBEntities1(); { TOCList = context.TOC.Where(element => element.Games == gameID).ToList(); tocDTOs = new List <TOCDTO>(); foreach (TOC toc in TOCList) { TOCDTO tocDTO = (TOCDTO)DTOConverter.Converter(new TOCDTO(), toc); tocDTOs.Add(tocDTO); } } } catch (EntityException ex) { exHandler.exceptionHandlerEntity(ex, "something happened while fetching the toclist"); } finally { context.Dispose(); } return(tocDTOs); }
internal int editEntry(EntryDTO alteredEntry) { var context = new rulesencyclopediaDBEntities1(); int result = -999999; { var entry = context.Entry.First(a => a.Id == alteredEntry.Id); entry.ParagraphNumber = alteredEntry.ParagraphNumber; entry.Headline = alteredEntry.Headline; entry.Text = alteredEntry.Text; entry.Revision = alteredEntry.Revision; entry.Editor = alteredEntry.Editor; result = context.SaveChanges(); } context.Dispose(); return(result); }
internal int editGame(Game alteredGame) { var context = new rulesencyclopediaDBEntities1(); Game game = null; { game = context.Game.First(a => a.Id == alteredGame.Id); game.Name = alteredGame.Name; game.Company = alteredGame.Company; game.TOC = alteredGame.TOC; game.Revision = alteredGame.Revision; game.Editor = alteredGame.Editor; context.SaveChanges(); } context.Dispose(); return(game.Id); }
internal int editTOC(TOC alteredTOC) { rulesencyclopediaDBEntities1 context = new rulesencyclopediaDBEntities1(); TOC toc = null; try { toc = context.TOC.First(a => a.Id == alteredTOC.Id); toc.Text = alteredTOC.Text; toc.Revision = alteredTOC.Revision; toc.Editor = alteredTOC.Editor; context.SaveChanges(); } catch (EntityException ex) { exHandler.exceptionHandlerEntity(ex, "Something went wrong when editing toc"); } finally { context.Dispose(); } return(toc.Id); }
internal EntryDTO getEntry(int ID) { Entry entry = null; EntryDTO entryDTO = null; rulesencyclopediaDBEntities1 context = null; try { context = new rulesencyclopediaDBEntities1(); { entry = context.Entry.Single(element => element.Id == ID); entryDTO = (EntryDTO)DTOConverter.Converter(new EntryDTO(), entry); } } catch (EntityException ex) { exHandler.exceptionHandlerEntity(ex, "something went wrong when getting the Entry"); } finally { context.Dispose(); } return(entryDTO); }
internal int postGame(Game game) { rulesencyclopediaDBEntities1 context = null; Game result = null; try { context = new rulesencyclopediaDBEntities1(); { //getting back the key for the created user. result = context.Game.Add(game); context.SaveChanges(); } } catch (EntityException ex) { exHandler.exceptionHandlerEntity(ex, "Something went wrong when creating new game"); } finally { context.Dispose(); } return(result.Id); }
internal TOCDTO getTOC(int ID) { TOC toc = null; rulesencyclopediaDBEntities1 context = null; try { context = new rulesencyclopediaDBEntities1(); { toc = context.TOC.Single(element => element.Id == ID); } } catch (EntityException ex) { exHandler.exceptionHandlerEntity(ex, "something went wrong when getting toc"); } finally { context.Dispose(); } TOCDTO tocDTO = (TOCDTO)DTOConverter.Converter(new TOCDTO(), toc); return(tocDTO); }
internal int deleteTOC(int ID) { rulesencyclopediaDBEntities1 context = new rulesencyclopediaDBEntities1(); TOC toc = null; try { toc = new TOC { Id = ID }; context.TOC.Attach(toc); context.TOC.Remove(toc); context.SaveChanges(); } catch (EntityException ex) { exHandler.exceptionHandlerEntity(ex, "Something went wrong while deleting the TOC"); } finally { context.Dispose(); } return(toc.Id); }