Example #1
0
        public Statistics Map(StatisticsDb statistics)
        {
            Statistics statistics_newType = new Statistics();

            #region Transfer main attributes

            statistics_newType.Id         = statistics.Id;
            statistics_newType.TimeSpent  = statistics.TimeSpent;
            statistics_newType.RunsAmount = statistics.RunsAmount;
            statistics_newType.UserRecord = statistics.UserRecord;

            #endregion

            #region Transfering interop attributes

            statistics_newType.User = new User()
            {
                Id = statistics.IdUser
            };
            statistics_newType.Game = new Game()
            {
                Id = statistics.IdGame
            };

            #endregion

            return(statistics_newType);
        }
        // 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);
        }
 /// <summary>
 /// Converts <see cref="StatisticsDb"/> model  to the <see cref="UserStatistics"/> one.
 /// </summary>
 /// <param name="statistics"><see cref="StatisticsDb"/> statistics to convert.</param>
 /// <returns>Converted <see cref="UserStatistics"/> statistics.</returns>
 public static UserStatistics ToUserStatistics(StatisticsDb statistics)
 {
     return(new UserStatistics(
                statistics.UserId,
                statistics.History,
                statistics.RockCount,
                statistics.PaperCount,
                statistics.ScissorsCount,
                statistics.GameTime));
 }
        public Statistics Get(long id)
        {
            StatisticsDb statistics          = statisticsDAO.GetExtended(id);
            Statistics   statistics_newTyped = null;

            if (statistics != null)
            {
                statistics_newTyped = mapper.Map(statistics);
            }

            return(statistics_newTyped);
        }
        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);
        }
Example #6
0
        public StatisticsDb Get(long id)
        {
            StatisticsDb statistics = null;

            List <EntityORM> entities = (List <EntityORM>)(crud.Read(table, attributes, new DbTools.WhereRequest[] { new DbTools.WhereRequest(idColumn, DbTools.RequestOperator.Equal, id) }));

            if (entities.Any())
            {
                EntityMapping.Map(entities[0], out statistics);
            }

            return(statistics);
        }
        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.");
            }
        }
Example #8
0
        public static EntityORM Map(StatisticsDb statistics, HashSet <string> attributes)
        {
            EntityORM entity = new EntityORM();

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


                switch (attribute)
                {
                case "IDUSER":
                    value = statistics.IdUser;
                    break;

                case "IDGAME":
                    value = statistics.IdGame;
                    break;

                case "RUNSAMOUNT":
                    value = statistics.RunsAmount;
                    break;

                case "TIMESPENT":
                    value = statistics.TimeSpent;
                    break;

                case "USERRECORD":
                    value = statistics.UserRecord;
                    break;

                default:
                    break;
                }

                entity.attributeValue.Add(attribute, value);
            }
            return(entity);
        }
Example #9
0
        public static void Map(EntityORM entity, out StatisticsDb statistics)
        {
            statistics = new StatisticsDb();

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

                case "IDUSER":
                    statistics.IdUser = Convert.ToInt64(aV.Value);
                    break;

                case "IDGAME":
                    statistics.IdGame = Convert.ToInt64(aV.Value);
                    break;

                case "RUNSAMOUNT":
                    statistics.RunsAmount = Convert.ToInt64(aV.Value);
                    break;

                case "TIMESPENT":
                    statistics.TimeSpent = (decimal)aV.Value;
                    break;

                case "USERRECORD":
                    statistics.UserRecord = Convert.ToInt64(aV.Value);
                    break;

                default:
                    break;
                }
            }
        }
        /// <summary>
        /// Return the MessageDb object with interop properties
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public StatisticsDb GetExtended(long id)
        {
            StatisticsDb statistics = Get(id);

            return(statistics);
        }
        public void Update(Statistics statistics)
        {
            StatisticsDb statisticsDb = mapper.Map(statistics);

            statisticsDAO.Update(statisticsDb);
        }
        public long Create(Statistics statistics)
        {
            StatisticsDb statisticsDb = mapper.Map(statistics);

            return(statisticsDAO.Save(statisticsDb));
        }