コード例 #1
0
ファイル: ModelsMapper.cs プロジェクト: vanmxpx/ISDPlatform
        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);
        }
コード例 #2
0
        // 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);
        }
コード例 #3
0
 /// <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));
 }
コード例 #4
0
        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);
        }
コード例 #5
0
        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);
        }
コード例 #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);
        }
コード例 #7
0
        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.");
            }
        }
コード例 #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);
        }
コード例 #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;
                }
            }
        }
コード例 #10
0
        /// <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);
        }
コード例 #11
0
        public void Update(Statistics statistics)
        {
            StatisticsDb statisticsDb = mapper.Map(statistics);

            statisticsDAO.Update(statisticsDb);
        }
コード例 #12
0
        public long Create(Statistics statistics)
        {
            StatisticsDb statisticsDb = mapper.Map(statistics);

            return(statisticsDAO.Save(statisticsDb));
        }