Beispiel #1
0
        /// <summary>
        /// Method to add a metric mapping to database
        /// </summary>
        /// <param name="metricMappingItem">metric mapping to be added</param>
        /// <param name="userName">logged in user name</param>
        private void AddMetricMapping(MetricMappingItem metricMappingItem, string userName)
        {
            int loggedInUserId = userRepository.GetAll().FirstOrDefault(
                x => x.AccountName == userName).Id;

            var metricMapping = new MetricMapping()
            {
                BusinessSegmentId = metricMappingItem.BusinessSegmentId.Value,
                DivisionId        = metricMappingItem.DivisionId.Value,
                FacilityId        = metricMappingItem.FacilityId.Value,
                ProductLineId     = metricMappingItem.ProductLineId.Value,
                DepartmentId      = metricMappingItem.DepartmentId.Value,
                ProcessId         = metricMappingItem.ProcessId.Value,
                KPIId             = metricMappingItem.KPIId.Value,
                MetricId          = metricMappingItem.MetricId.Value,
                CreatedBy         = loggedInUserId,
                LastModifiedBy    = loggedInUserId,
                LastModifiedOn    = TimeZoneUtility.GetCurrentTimestamp(),
                CreatedOn         = TimeZoneUtility.GetCurrentTimestamp(),
                IsActive          = true
            };

            metricMappingRepository.AddOrUpdate(metricMapping);
            metricMappingRepository.Save();
        }
Beispiel #2
0
        /// <summary>
        /// Method to update a metric mapping
        /// </summary>
        /// <param name="MetricMappingItem">Metric Mapping item to update</param>
        /// <param name="userName">logged in user name</param>
        private void UpdateMetricMapping(MetricMappingItem metricMappingItem, string userName)
        {
            int loggedInUserId = userRepository.GetAll().FirstOrDefault(
                x => x.AccountName == userName).Id;
            //get existing metric mapping details
            var existingMetricMapping = metricMappingRepository.Get(metricMappingItem.Id.Value);

            existingMetricMapping.BusinessSegmentId = metricMappingItem.BusinessSegmentId.Value;
            existingMetricMapping.DivisionId        = metricMappingItem.DivisionId.Value;
            existingMetricMapping.FacilityId        = metricMappingItem.FacilityId.Value;
            existingMetricMapping.ProductLineId     = metricMappingItem.ProductLineId.Value;
            existingMetricMapping.DepartmentId      = metricMappingItem.DepartmentId.Value;
            existingMetricMapping.ProcessId         = metricMappingItem.ProcessId.Value;
            existingMetricMapping.KPIId             = metricMappingItem.KPIId.Value;
            existingMetricMapping.MetricId          = metricMappingItem.MetricId.Value;
            existingMetricMapping.IsActive          = metricMappingItem.IsActive;
            existingMetricMapping.LastModifiedOn    = TimeZoneUtility.GetCurrentTimestamp();
            existingMetricMapping.LastModifiedBy    = loggedInUserId;
            metricMappingRepository.Save();
        }
Beispiel #3
0
        /// <summary>
        /// Validates an update request for a metric
        /// </summary>
        /// <param name="metricItem">Metric item to update</param>
        /// <returns>List of validation errors of exists</returns>
        private string ValidateMetricMappingUpdateRequest(MetricMappingItem metricMappingItem)
        {
            string validationError = string.Empty;
            //get existing metric mapping details
            var existingMetricMapping = metricMappingRepository.Get(metricMappingItem.Id.Value);

            if (existingMetricMapping == null)
            {
                validationError = Constants.MetricMappingNotFound;
            }
            else
            {
                // If the request is to update the metric name it self, check if the
                // new name already exists or not
                if (!(existingMetricMapping.BusinessSegmentId == metricMappingItem.BusinessSegmentId &&
                      existingMetricMapping.DivisionId == metricMappingItem.DivisionId &&
                      existingMetricMapping.FacilityId == metricMappingItem.FacilityId &&
                      existingMetricMapping.ProductLineId == metricMappingItem.ProductLineId &&
                      existingMetricMapping.DepartmentId == metricMappingItem.DepartmentId &&
                      existingMetricMapping.ProcessId == metricMappingItem.ProcessId &&
                      existingMetricMapping.KPIId == metricMappingItem.KPIId &&
                      existingMetricMapping.MetricId == metricMappingItem.MetricId))
                {
                    //Check if the mapping set requested already exists
                    if (metricMappingRepository.GetAll()
                        .Any(mm => mm.BusinessSegmentId == metricMappingItem.BusinessSegmentId &&
                             mm.DivisionId == metricMappingItem.DivisionId &&
                             mm.FacilityId == metricMappingItem.FacilityId &&
                             mm.ProductLineId == metricMappingItem.ProductLineId &&
                             mm.DepartmentId == metricMappingItem.DepartmentId &&
                             mm.ProcessId == metricMappingItem.ProcessId &&
                             mm.KPIId == metricMappingItem.KPIId &&
                             mm.MetricId == metricMappingItem.MetricId))
                    {
                        validationError = Constants.MetricMappingExists;
                    }
                }
            }
            return(validationError);
        }