예제 #1
0
        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);
        }
예제 #2
0
        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);
        }
예제 #3
0
        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);
        }
예제 #4
0
        internal List <UserDTO> getUserList()
        {
            List <User>    userList = null;
            List <UserDTO> userDTOs = null;
            rulesencyclopediaDBEntities1 context = new rulesencyclopediaDBEntities1();

            try
            {
                userList = context.User.ToList();
                userDTOs = new List <UserDTO>();
                foreach (User user in userList)
                {
                    UserDTO userDTO = (UserDTO)DTOConverter.Converter(new UserDTO(), user);
                    userDTOs.Add(userDTO);
                }
            }
            catch (EntityException ex)
            {
                exHandler.exceptionHandlerEntity(ex, "Something went wrong when getting all the users");
            }
            finally
            {
                context.Dispose();
            }
            return(userDTOs);
        }
예제 #5
0
        // GET api/login?UserName=pepepe&Password=1234
        public HttpResponseMessage Get([FromUri] string UserName, [FromUri] string Password)
        {
            //Check if username exists
            var dbUser = userDao.checkUserName(UserName);

            //If it does
            if (dbUser != null)
            {
                //check if the password when hashed and salted is equal to the password for the user from the db
                HashAndSalt pwSecurity = new HashAndSalt();
                if (pwSecurity.AreEqual(Password, dbUser.Password, dbUser.Salt))
                {
                    //transfer the db object values to a UserDTO object
                    UserDTO  user  = (UserDTO)DTOConverter.Converter(new UserDTO(), dbUser);
                    TokenDTO token = CheckToken.Instance.userLogin(user);
                    // string token = userDao.getUserFromLogin(UserName, user.Password);
                    if (token != null)
                    {
                        response = Request.CreateResponse(HttpStatusCode.OK, token.token);
                    }
                    else
                    {
                        response = Request.CreateResponse(HttpStatusCode.InternalServerError, "Problem creating token");
                    }
                }
                else
                {
                    response = Request.CreateResponse(HttpStatusCode.Forbidden, "Password is wrong. Try again");
                }
            }
            else
            {
                response = Request.CreateResponse(HttpStatusCode.NoContent, "User does not exist");
            }

            return(response);
        }