예제 #1
0
        ///<summary>
        ///Maps properties from UserConnectionDb object to EntityORM object
        ///</summary>
        public static EntityORM Map(UsersConnectionDb userConnection, HashSet <string> attributes)
        {
            EntityORM entity = new EntityORM();

            foreach (string attribute in attributes)
            {
                object value = null;    // attribute value

                switch (attribute)
                {
                case "AREFRIENDS":
                    value = (userConnection.AreFriends) ? "\'y\'" : "\'n\'";
                    break;

                case "BLACKLISTED":
                    value = (userConnection.BlackListed) ? "\'y\'": "\'n\'";
                    break;

                case "IDUSER1":
                    value = $"\'{ userConnection.IdUser1}\'";
                    break;

                case "IDUSER2":
                    value = $"\'{userConnection.IdUser2}\'";
                    break;

                default:
                    break;
                }

                entity.attributeValue.Add(attribute, value);
            }

            return(entity);
        }
예제 #2
0
        public bool Unsubscribe(UsersConnectionDb usersConnection)
        {
            var where_attributes = new Dictionary <string, object>()
            {
                { "IDUSER1", usersConnection.IdUser1 },
                { "IDUSER2", usersConnection.IdUser2 }
            };

            bool isUnsubscribed = Delete(table, attributes, where_attributes);

            UsersConnectionDb symmetricConnection = new UsersConnectionDb()
            {
                IdUser1 = usersConnection.IdUser2, IdUser2 = usersConnection.IdUser1
            };

            if (ConnectionExists(symmetricConnection))
            {
                where_attributes["IDUSER1"]    = symmetricConnection.IdUser1;
                where_attributes["IDUSER2"]    = symmetricConnection.IdUser2;
                symmetricConnection.AreFriends = false;

                EntityORM symmetricConnection_newTyped = Mapping.EntityMapping.Map(symmetricConnection, attributes);

                // Making sure that ID value is not touched.
                symmetricConnection_newTyped.attributeValue.Remove("ID");

                Update(table, attributes, where_attributes, symmetricConnection_newTyped);
            }

            return(isUnsubscribed);
        }
예제 #3
0
        public static EntityORM Map(VerificationDb verify, HashSet <string> attributes)
        {
            EntityORM entity = new EntityORM();

            foreach (string attribute in attributes)
            {
                object value = null;

                switch (attribute)
                {
                case "EMAIL":
                    value = $"\'{verify.Email}\'";
                    break;

                case "TOKEN":
                    value = $"\'{verify.Token}\'";
                    break;

                case "ENDVERIFYDATE":
                    value = $"TO_TIMESTAMP(\'{verify.EndVerifyDate.ToString("dd.MM.yyyy HH:mm:ss")}\', 'DD.MM.YYYY HH24:MI:SS')";
                    break;
                }

                entity.attributeValue.Add(attribute, value);
            }

            return(entity);
        }
예제 #4
0
        ///<summary>
        ///Maps properties from EntityORM object to UseConnectionrDb object
        ///</summary>
        public static void Map(EntityORM entity, out UsersConnectionDb userConnection)
        {
            userConnection = new UsersConnectionDb();

            foreach (KeyValuePair <string, object> aV in entity.attributeValue)
            {
                switch (aV.Key)        // attribute
                {
                case "ID":
                    userConnection.Id = Convert.ToInt64(aV.Value);
                    break;

                case "IDUSER1":
                    userConnection.IdUser1 = Convert.ToInt64(aV.Value);
                    break;

                case "IDUSER2":
                    userConnection.IdUser2 = Convert.ToInt64(aV.Value);
                    break;

                case "AREFRIENDS":
                    userConnection.AreFriends = ((string)aV.Value == "y") ? true : false;
                    break;

                case "BLACKLISTED":
                    userConnection.BlackListed = ((string)aV.Value == "y") ? true : false;
                    break;

                default:
                    break;
                }
            }
        }
        // Here they will be

        #endregion
        #endregion

        public long Save(GameReviewDb gameReview)
        {
            EntityORM entity = EntityMapping.Map(gameReview, attributes);

            entity.attributeValue.Remove("ID");     // getting sure that ID value is not touched

            long idGameReview = crud.Create(table, idColumn, entity);

            return(idGameReview);
        }
        // Here they will be

        #endregion
        #endregion

        public long Save(StatisticsDb statistics)
        {
            EntityORM entity = EntityMapping.Map(statistics, attributes);

            entity.attributeValue.Remove("ID");     // getting sure that ID value is not touched

            long idStatistic = crud.Create(table, idColumn, entity);

            return(idStatistic);
        }
예제 #7
0
        public long Save(VerificationDb verify)
        {
            EntityORM entity = EntityMapping.Map(verify, attributes);

            long verify_id = crud.Create(table, idColumn, entity, false);

            logger.Info($"User with id = {verify_id} was created");

            return(verify_id);
        }
예제 #8
0
        public long Save(GameDb game)
        {
            EntityORM entity = EntityMapping.Map(game, attributes);

            // Making sure that ID value is not touched.
            entity.attributeValue.Remove("ID");

            long idGame = crud.Create(table, idColumn, entity);

            return(idGame);
        }
예제 #9
0
        // Here they will be

        #endregion

        #endregion

        public long Save(ChatDb chat)
        {
            EntityORM entity = EntityMapping.Map(chat, attributes);

            // Making sure that ID value is not touched.
            entity.attributeValue.Remove("ID");

            long idChat = crud.Create(table, idColumn, entity);

            return(idChat);
        }
예제 #10
0
        // Here they will be

        #endregion
        #endregion

        public long Save(UserReviewDb userReview)
        {
            EntityORM entity = EntityMapping.Map(userReview, attributes);

            // Making sure that ID value is not touched.
            entity.attributeValue.Remove("ID");

            long idUserReview = crud.Create(table, idColumn, entity);

            return(idUserReview);
        }
예제 #11
0
        public VerificationDb Get(object id)
        {
            VerificationDb verify = null;
            EntityORM      entity = crud.Read(id, "TOKEN", attributes, table);

            if (entity != null)
            {
                EntityMapping.Map(entity, out verify);
            }

            return(verify);
        }
예제 #12
0
        public UserReviewDb Get(long id)
        {
            UserReviewDb userReview = null;

            EntityORM entity = crud.Read(id, idColumn, attributes, table);

            if (entity != null)
            {
                EntityMapping.Map(entity, out userReview);
            }

            return(userReview);
        }
예제 #13
0
        public GameDb Get(object id)
        {
            GameDb game = null;

            EntityORM entity = crud.Read(id, idColumn, attributes, table);

            if (entity != null)
            {
                EntityMapping.Map(entity, out game);
            }

            return(game);
        }
예제 #14
0
        public MessageDb Get(long id)
        {
            MessageDb message = null;

            EntityORM entity = crud.Read(id, idColumn, attributes, table);

            if (entity != null)
            {
                EntityMapping.Map(entity, out message);
            }

            return(message);
        }
예제 #15
0
        public GameReviewDb Get(long id)
        {
            GameReviewDb gameReview = null;

            EntityORM entity = crud.Read(id, idColumn, attributes, table);

            if (entity != null)
            {
                EntityMapping.Map(entity, out gameReview);
            }

            return(gameReview);
        }
예제 #16
0
        public long Save(UserDb user)
        {
            EntityORM entity = EntityMapping.Map(user, attributes);

            // Making sure that ID value is not touched.
            entity.attributeValue.Remove("ID");

            long user_id = crud.Create(table, idColumn, entity);

            logger.Info($"User with id = {user_id} was created");

            return(user_id);
        }
예제 #17
0
        public ChatDb Get(long id)
        {
            ChatDb chat = null;

            EntityORM entity = crud.Read(id, idColumn, attributes, table);

            if (entity != null)
            {
                EntityMapping.Map(entity, out chat);
            }

            return(chat);
        }
        public StatisticsDb Get(long id)
        {
            StatisticsDb statistics = null;

            EntityORM entity = crud.Read(id, idColumn, attributes, table);

            if (entity != null)
            {
                EntityMapping.Map(entity, out statistics);
            }

            return(statistics);
        }
예제 #19
0
        private bool ConnectionExists(UsersConnectionDb usersConnection)
        {
            var where_attributes = new Dictionary <string, object>()
            {
                { "IDUSER1", usersConnection.IdUser1 },
                { "IDUSER2", usersConnection.IdUser2 }
            };


            EntityORM usersConnection_newTyped = Get(table, attributes, where_attributes);

            return(usersConnection_newTyped != null);
        }
        public bool CreateConnection(UsersConnectionDb usersConnection)
        {
            if (ConnectionExists(usersConnection))
            {
                return(false);
            }

            bool isCreated = false;

            UsersConnectionDb symmetricConnection = new UsersConnectionDb()
            {
                IdUser1 = usersConnection.IdUser2, IdUser2 = usersConnection.IdUser1
            };
            var where_attributes = new Dictionary <string, object>()
            {
                { "IDUSER1", symmetricConnection.IdUser2 },
                { "IDUSER2", symmetricConnection.IdUser1 }
            };


            EntityORM entity = Get(table, attributes, where_attributes);

            if (entity != null)
            {
                if ((bool)entity.attributeValue["BLACKLISTED"])
                {
                    return(isCreated);
                }

                where_attributes = new Dictionary <string, object>()
                {
                    { "IDUSER1", usersConnection.IdUser1 },
                    { "IDUSER2", usersConnection.IdUser2 }
                };

                symmetricConnection.AreFriends = true;

                EntityORM symmetricConnection_newTyped = Mapping.EntityMapping.Map(symmetricConnection, attributes);

                Update(table, attributes, where_attributes, symmetricConnection_newTyped);

                usersConnection.AreFriends = true;
            }

            isCreated = Save(usersConnection);

            return(isCreated);
        }
예제 #21
0
        ///<summary>
        ///Maps properties from GameDb object to EntityORM object
        ///</summary>
        public static EntityORM Map(GameDb game, HashSet <string> attributes)
        {
            EntityORM entity = new EntityORM();

            foreach (string attribute in attributes)
            {
                object value = null;        // attribute value

                switch (attribute)
                {
                case "NAME":
                    value = $"\'{game.Name}\'";
                    break;

                case "DESCRIPTION":
                    value = $"\'{game.Description}\'";
                    break;

                case "GENRE":
                    value = $"\'{game.Genre}\'";
                    break;

                case "LINK":
                    value = $"\'{game.Link}\'";
                    break;

                case "LOGOURL":
                    value = $"\'{game.LogoURL}\'";
                    break;

                case "COVERURL":
                    value = $"\'{game.CoverURL}\'";
                    break;

                case "ISVERIFIED":
                    value = (game.IsVerified) ? "\'y\'" : "\'n\'";
                    break;

                default:
                    break;
                }

                entity.attributeValue.Add(attribute, value);
            }

            return(entity);
        }
예제 #22
0
        public void Update(GameReviewDb gameReview)
        {
            EntityORM entity = EntityMapping.Map(gameReview, attributes);

            entity.attributeValue.Remove("ID");     // getting sure that ID value is not touched

            bool ifUpdated = crud.Update(gameReview.Id, table, idColumn, entity);

            if (ifUpdated)
            {
                logger.Info($"Game review with id={gameReview.Id} was successfully updated.");
            }
            else
            {
                logger.Info($"Updating gameReview with id={gameReview.Id} was failed.");
            }
        }
        public void Update(StatisticsDb statistics)
        {
            EntityORM entity = EntityMapping.Map(statistics, attributes);

            entity.attributeValue.Remove("ID");     // getting sure that ID value is not touched

            bool ifUpdated = crud.Update(statistics.Id, table, idColumn, entity);

            if (ifUpdated)
            {
                logger.Info($"Game statistics with id={statistics.Id} was successfully updated.");
            }
            else
            {
                logger.Info($"Updating statistics with id={statistics.Id} was failed.");
            }
        }
예제 #24
0
        public void Update(ChatDb chat)
        {
            EntityORM entity = EntityMapping.Map(chat, attributes);

            entity.attributeValue.Remove("ID");     // getting sure that ID value is not touched

            bool ifUpdated = crud.Update(chat.Id, table, idColumn, entity);

            if (ifUpdated)
            {
                logger.Info($"Game with id={chat.Id} was successfully updated.");
            }
            else
            {
                logger.Info($"Updating chat with id={chat.Id} was failed.");
            }
        }
예제 #25
0
        ///<summary>
        ///Maps properties from EntityORM object to GameDb object
        ///</summary>
        public static void Map(EntityORM entity, out GameDb game)
        {
            game = new GameDb();

            foreach (KeyValuePair <string, object> aV in entity.attributeValue)
            {
                switch (aV.Key)  // entity attribute
                {
                case "ID":
                    game.Id = Convert.ToInt64(aV.Value);
                    break;

                case "NAME":
                    game.Name = aV.Value.ToString();
                    break;

                case "DESCRIPTION":
                    game.Description = aV.Value.ToString();
                    break;

                case "GENRE":
                    game.Genre = aV.Value.ToString();
                    break;

                case "LINK":
                    game.Link = aV.Value.ToString();
                    break;

                case "LOGOURL":
                    game.LogoURL = aV.Value.ToString();
                    break;

                case "COVERURL":
                    game.CoverURL = aV.Value.ToString();
                    break;

                case "ISVERIFIED":
                    game.IsVerified = ((string)aV.Value == "y") ? true : false;
                    break;

                default:
                    break;
                }
            }
        }
예제 #26
0
        public bool CreateConnection(UsersConnectionDb usersConnection)
        {
            if (ConnectionExists(usersConnection))
            {
                return(false);
            }

            bool isCreated = false;

            UsersConnectionDb symmetricConnection = new UsersConnectionDb()
            {
                IdUser1 = usersConnection.IdUser2, IdUser2 = usersConnection.IdUser1
            };
            var where_attributes = new Dictionary <string, object>()
            {
                { "IDUSER1", symmetricConnection.IdUser1 },
                { "IDUSER2", symmetricConnection.IdUser2 }
            };


            EntityORM entity = Get(table, attributes, where_attributes);

            if (entity != null)
            {
                if (DbTools.ProcessBoolean(entity.attributeValue["BLACKLISTED"]))
                {
                    return(isCreated);
                }

                symmetricConnection.AreFriends = true;

                EntityORM symmetricConnection_newTyped = Mapping.EntityMapping.Map(symmetricConnection, attributes);

                // Making sure that ID value is not touched.
                symmetricConnection_newTyped.attributeValue.Remove("ID");

                Update(table, attributes, where_attributes, symmetricConnection_newTyped);

                usersConnection.AreFriends = true;
            }

            isCreated = Save(usersConnection);

            return(isCreated);
        }
예제 #27
0
        public void Update(MessageDb message)
        {
            EntityORM entity = EntityMapping.Map(message, attributes);

            // Making sure that ID value is not touched
            entity.attributeValue.Remove("ID");

            bool ifUpdated = crud.Update(message.Id, table, idColumn, entity);

            if (ifUpdated)
            {
                logger.Info($"Game with id={message.Id} was successfully updated.");
            }
            else
            {
                logger.Info($"Updating message with id={message.Id} was failed.");
            }
        }
예제 #28
0
        public UserDb GetByUniqueAttribute(object attribute_value, string attribute_name)
        {
            UserDb user = null;

            if (!unique_attributes.Contains(attribute_name))
            {
                logger.Info($"{attribute_name} is not unique attribute. GET-method failed..");
                return(user);
            }

            EntityORM entity = crud.Read(attribute_value, attribute_name, attributes, table);

            if (entity != null)
            {
                EntityMapping.Map(entity, out user);
            }

            return(user);
        }
예제 #29
0
        /// <summary>
        /// Gets all the records which satisfy sql-expression with WHERE keyword. In the other way returns null.
        /// </summary>
        /// <param name="table"></param>
        /// <param name="attributes"></param>
        /// <param name="where_attributes"></param>
        /// <returns></returns>
        private List <EntityORM> GetAll(string table, HashSet <string> attributes, Dictionary <string, object> where_attributes)
        {
            List <EntityORM> entities = null;

            try
            {
                dbConnect.OpenConnection();

                string where_part    = string.Join(" AND ", where_attributes.Select(x => string.Format("{0}={1}", x.Key, x.Value)));
                string sqlExpression = String.Format("SELECT * FROM {0} WHERE {1}", table, where_part);

                OracleCommand command = new OracleCommand(sqlExpression, dbConnect.GetConnection());

                OracleDataReader reader = command.ExecuteReader();

                if (reader.Read())
                {
                    entities = new List <EntityORM>();

                    do
                    {
                        EntityORM entity = new EntityORM();
                        foreach (string attribute in attributes)
                        {
                            object value = reader[attribute];
                            entity.attributeValue.Add(attribute, value);
                        }

                        entities.Add(entity);
                    } while (reader.Read());
                }
            }
            catch (DbException ex)
            {
                logger.Info("Exception.Message: {0}", ex.Message);
            }
            finally
            {
                dbConnect.CloseConnection();
            }

            return(entities);
        }
예제 #30
0
        public bool Save(UsersConnectionDb usersConnection)
        {
            bool isSaved = false;

            EntityORM entity = EntityMapping.Map(usersConnection, attributes);

            // Making sure that ID value is not touched.
            entity.attributeValue.Remove("ID");

            long userConnection_id = crud.Create(table, idColumn, entity);

            if (userConnection_id != 0)
            {
                logger.Info($"UsersConnection with id = {userConnection_id} was created");
                isSaved = true;
            }

            return(isSaved);
        }