コード例 #1
0
        /// <summary>
        /// Method to add a metric to database
        /// </summary>
        /// <param name="metricItem">metric item to be added</param>
        /// <param name="userName">logged in user name</param>
        private void AddMetric(MetricItem metricItem, string userName)
        {
            int loggedInUserId = userRepository.GetAll().FirstOrDefault(
                x => x.AccountName == userName).Id;
            var metric = new Metric()
            {
                Name           = metricItem.Name,
                DataTypeId     = metricItem.DataType.Id.Value,
                GoalTypeId     = metricItem.GoalType.Id.Value,
                CreatedBy      = loggedInUserId,
                LastModifiedBy = loggedInUserId,
                CreatedOn      = TimeZoneUtility.GetCurrentTimestamp(),
                LastModifiedOn = TimeZoneUtility.GetCurrentTimestamp(),
                IsActive       = metricItem.IsActive
            };

            metricRepository.AddOrUpdate(metric);
            metricRepository.Save();
        }