Ejemplo n.º 1
0
        /// <summary>
        /// Method to validate whether Stretch Goal Targets must be on par or beat the
        /// monthly target based on the Goal type of the Metric
        /// </summary>
        /// <param name="metricId">Identifier of Metric</param>
        /// <param name="monthlyTargets">list of monthly targets</param>
        private void ValidateStrechGoalTarget(int metricId, List <MonthlyTargetItem> monthlyTargets)
        {
            var      metric      = metricRepository.Get(metricId);
            DateTime currentDate = TimeZoneUtility.GetCurrentTimestamp().Date;
            //check whether stretch goal is not entered for any current or future months
            bool isStretchGoalNotEntered = monthlyTargets.Any(x => (x.GoalValue.HasValue || x.DailyRateValue.HasValue) &&
                                                              !x.StretchGoalValue.HasValue &&
                                                              ((x.Month.Year == currentDate.Year && x.Month.Id >= currentDate.Month) ||
                                                               x.Month.Year > currentDate.Year));

            if (isStretchGoalNotEntered)
            {
                throw new NDMSBusinessException(Constants.StretchGoalEmptyErrorMessage);
            }

            foreach (var monthlyTarget in monthlyTargets)
            {
                if (monthlyTarget.StretchGoalValue != null)
                {
                    if (metric.GoalTypeId == Constants.GoalTypeEqualTo)
                    {
                        if (monthlyTarget.GoalValue != null && monthlyTarget.StretchGoalValue != monthlyTarget.GoalValue)
                        {
                            throw new NDMSBusinessException(Constants.TargetStretchGoalEqualToErrorMessage);
                        }
                        if (monthlyTarget.DailyRateValue != null && monthlyTarget.StretchGoalValue != monthlyTarget.DailyRateValue)
                        {
                            throw new NDMSBusinessException(Constants.DailyRateStretchGoalEqualToErrorMessage);
                        }
                    }
                    else if (metric.GoalTypeId == Constants.GoalTypeGreaterThanOrEqualTo)
                    {
                        if (monthlyTarget.GoalValue != null && (monthlyTarget.StretchGoalValue < monthlyTarget.GoalValue))
                        {
                            throw new NDMSBusinessException(Constants.TargetStretchGoalGreaterThanErrorMessage);
                        }
                        if (monthlyTarget.DailyRateValue != null && (monthlyTarget.StretchGoalValue < monthlyTarget.DailyRateValue))
                        {
                            throw new NDMSBusinessException(Constants.DailyRateStretchGoalGreaterThanErrorMessage);
                        }
                    }
                    else if (metric.GoalTypeId == Constants.GoalTypeLessThanOrEqualTo)
                    {
                        if (monthlyTarget.GoalValue != null && (monthlyTarget.StretchGoalValue > monthlyTarget.GoalValue))
                        {
                            throw new NDMSBusinessException(Constants.TargetStretchGoalLessThanErrorMessage);
                        }
                        if (monthlyTarget.DailyRateValue != null && (monthlyTarget.StretchGoalValue > monthlyTarget.DailyRateValue))
                        {
                            throw new NDMSBusinessException(Constants.DailyRatetStretchGoalLessThanErrorMessage);
                        }
                    }
                }
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Updates existing Holiday Pattern
        /// </summary>
        /// <param name="requestItem"></param>
        /// <param name="userName"></param>
        private void UpdateHolidayPattern(HolidayPatternItem requestItem, string userName)
        {
            var loggedInUserId = userRepository.GetAll().FirstOrDefault(x =>
                                                                        x.AccountName == userName).Id;
            var existingPattern = holidayPatternRepository.Get(requestItem.Id.Value);

            existingPattern.Name           = requestItem.Name;
            existingPattern.IsActive       = requestItem.IsActive;
            existingPattern.LastModifiedOn = TimeZoneUtility.GetCurrentTimestamp();
            existingPattern.LastModifiedBy = loggedInUserId;
            holidayPatternRepository.Save();
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Updates the existing monthly target.
        /// </summary>
        /// <param name="existingMonthlyTarget">The existing monthly target.</param>
        /// <param name="targetValue">The target value.</param>
        /// <param name="targetEntryDate">The target entry date.</param>
        /// <param name="loggedInUserId">The logged in user identifier.</param>
        /// <returns></returns>
        private MonthlyTarget UpdateExistingMonthlyRollupTarget(MonthlyTarget existingMonthlyTarget, int loggedInUserId)
        {
            DateTime curTimestamp = TimeZoneUtility.GetCurrentTimestamp();

            existingMonthlyTarget.LastModifiedBy = loggedInUserId;
            existingMonthlyTarget.LastModifiedOn = curTimestamp;
            var monthlyTargetHistory = TargetConverters.ConvertMonthlyTargetToMonthlyTargetHistory(existingMonthlyTarget);

            monthlyTargetHistory.TargetId = existingMonthlyTarget.TargetId;
            existingMonthlyTarget.MonthlyTargetHistory.Add(monthlyTargetHistory);
            return(existingMonthlyTarget);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Method to get active counter measure count for a KPI which belongs to scorecard
        /// </summary>
        /// <param name="scorecardId">Scorecard Id</param>
        /// <param name="kpiId">KPI Id</param>
        /// <returns>counter measure count</returns>
        public int GetCounterMeasureCount(int scorecardId, int kpiId)
        {
            DateTime currentDate = TimeZoneUtility.GetCurrentTimestamp().Date;

            //get count of all counter measure which are not confirmed
            int counterMeasureCount = counterMeasureRepository.GetAll()
                                      .Count(x => x.ScorecardId == scorecardId &&
                                             x.KPIId == kpiId &&
                                             x.CounterMeasureStatusId != Constants.CounterMeasureStatusConfirmed);

            return(counterMeasureCount);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Validates the list of updated holidays
        /// </summary>
        /// <param name="holidays"></param>
        private void ValidateHolidaysListUpdateRequest(HolidayPatternInfoRequest request)
        {
            var existingHolidays = holidayPatternRepository.Get(request.HolidayPatternId)
                                   .Holidays.Where(x => x.IsActive).Select(y => y.Date).ToList();

            if (request.Holidays.Where(x =>
                                       x.Date <= TimeZoneUtility.GetCurrentTimestamp().Date).Any(y =>
                                                                                                 !existingHolidays.Contains(y)))
            {
                throw new NDMSBusinessException(ValidationMessages.PastDateError);
            }
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Method to convert Counter Measure Comment to Counter Measure Comment Entity
        /// </summary>
        /// <param name="comment">comment</param>
        /// <param name="loggedInUserId">Logged In UserId</param>
        /// <returns></returns>
        public static CounterMeasureComment ConvertCommentToCounterMeasureComment(string comment,
                                                                                  int loggedInUserId)
        {
            var counterMeasureComment = new CounterMeasureComment()
            {
                Comment        = comment,
                CreatedBy      = loggedInUserId,
                LastModifiedBy = loggedInUserId,
                CreatedOn      = TimeZoneUtility.GetCurrentTimestamp(),
                LastModifiedOn = TimeZoneUtility.GetCurrentTimestamp()
            };

            return(counterMeasureComment);
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Deletes the recordable details for the given date.
        /// </summary>
        /// <param name="target">The target.</param>
        /// <param name="recordableDate">The recordable date.</param>
        /// <param name="loggedInUserId">The logged in user identifier.</param>
        private void DeleteRecordablesOfDay(Target target, DateTime recordableDate, int loggedInUserId)
        {
            var scorecardRecordable = recordableRepository.GetAll()
                                      .Where(x => x.ScorecardId == target.ScorecardId &&
                                             x.RecordableDate == recordableDate && !x.IsManual && x.IsActive).FirstOrDefault();

            if (scorecardRecordable != null)
            {
                scorecardRecordable.IsActive       = false;
                scorecardRecordable.LastModifiedBy = loggedInUserId;
                scorecardRecordable.LastModifiedOn = TimeZoneUtility.GetCurrentTimestamp();
                recordableRepository.AddOrUpdate(scorecardRecordable);
            }
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Get Month To date performance to determine Goal Value
        /// </summary>
        /// <param name="target"></param>
        /// <param name="year"></param>
        /// <param name="month"></param>
        /// <returns></returns>
        public decimal?GetMonthToDateGoalValue(Target target, int year, int monthId)
        {
            decimal?goal          = null;
            var     currentDate   = TimeZoneUtility.GetCurrentTimestamp();
            var     day           = currentDate.Day;
            var     monthlyTarget = target.MonthlyTargets.FirstOrDefault(x => x.TargetId == target.Id && x.Month == monthId);

            if (monthlyTarget != null)
            {
                if (!target.MTDPerformanceTrackingMethodId.HasValue)
                {
                    return(monthlyTarget.MaxGoalValue);
                }

                switch ((MTDPerformanceTrackingMethod)target.MTDPerformanceTrackingMethodId)
                {
                case MTDPerformanceTrackingMethod.Cumulative:
                {
                    goal = goalCalculator.CalculateCumulativeMTDGoal(target, monthId);
                }
                break;

                case MTDPerformanceTrackingMethod.Average:
                {
                    goal = goalCalculator.CalculateAverageMTDGoal(target, monthId);
                }
                break;

                case MTDPerformanceTrackingMethod.Latest:
                {
                    goal = goalCalculator.GetDailyMTDGoal(target, monthId);
                }
                break;

                default: break;
                }
                if (goal.HasValue)
                {
                    if (target.Metric.DataTypeId == Constants.DataTypeWholeNumber)
                    {
                        goal = Math.Round(goal.Value, 0, MidpointRounding.AwayFromZero);
                    }
                    else
                    {
                        goal = Math.Round(goal.Value, 2, MidpointRounding.AwayFromZero);
                    }
                }
            }
            return(goal);
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Gets the required Holiday pattern and holidays associated
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        private HolidayPatternItem GetHolidayPatternHolidays(int id)
        {
            var holidayPatternItem = holidayPatternRepository.GetAll().Where(x =>
                                                                             x.Id == id).Select(m => new HolidayPatternItem
            {
                Id       = m.Id,
                Name     = m.Name,
                IsActive = m.IsActive,
                Holidays = m.Holidays.Where(n => n.IsActive).Select(y => y.Date).ToList()
            }).FirstOrDefault();

            holidayPatternItem.CurrentDate = TimeZoneUtility.GetCurrentTimestamp();
            return(holidayPatternItem);
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Method to update daily actual and monthly entry
        /// </summary>
        /// <param name="actualRequest">daily actual request</param>
        /// <param name="goalTypeId">metric goal type id</param>
        /// <param name="dataTypeId">metric data type id</param>
        /// <param name="userName">logged in user name</param>
        public virtual void UpdateDailyActual(ActualItem actualRequest, int goalTypeId,
                                              int dataTypeId, string userName)
        {
            //get logged in user id
            int loggedInUserId = userRepository.GetAll().FirstOrDefault(
                x => x.AccountName == userName).Id;
            //get existing daily actual
            var existingDailyActual = dailyActualRepository.Get(actualRequest.Id.Value);

            var     target = targetRepository.Get(actualRequest.TargetId);
            decimal?actualValueToBeCompared = actualRequest.ActualValue;
            decimal?goalValueToBeCompared   = actualRequest.GoalValue;
            decimal?goalValueToBeSaved      = actualRequest.GoalValue;

            //get cumulative actual & goal value that needs to be compared in case of cumulative plotting
            if (target.GraphPlottingMethodId == Constants.GraphPlottingMethodCumulative)
            {
                actualValueToBeCompared = actualCalculator.CalculateCumulativeActual(
                    actualRequest.TargetId, actualRequest.Date, actualRequest.ActualValue);
                goalValueToBeCompared = goalCalculator.CalculateCumulativeGoal(
                    target, actualRequest.Date);
                goalValueToBeSaved = goalCalculator.GetDailyGoal(actualRequest.TargetId,
                                                                 actualRequest.Date.Month, actualRequest.Date.Day);
            }

            //update daily actual with new changes
            existingDailyActual.ActualValue = actualRequest.ActualValue;
            existingDailyActual.GoalValue   = goalValueToBeSaved;
            existingDailyActual.Status      = (actualValueToBeCompared.HasValue) ?
                                              TargetActualComparer.GetActualStatus(goalValueToBeCompared,
                                                                                   actualValueToBeCompared, goalTypeId) : ActualStatus.NotEntered;
            existingDailyActual.LastModifiedOn = TimeZoneUtility.GetCurrentTimestamp();
            existingDailyActual.LastModifiedBy = loggedInUserId;
            //add history of daily actual
            existingDailyActual.DailyActualHistory.Add(
                ActualConverters.ConvertDailyActualToDailyActualHistory(existingDailyActual));

            // Add/Update corresponding monthly actual
            var monthlyActual = AdjustMonthlyActual(actualRequest, goalTypeId,
                                                    dataTypeId, loggedInUserId);

            // If it is a new monthly actual entry, add explicitly
            if (monthlyActual.Id == 0)
            {
                monthlyActualRepository.AddOrUpdate(monthlyActual);
            }

            dailyActualRepository.Save();
        }
Ejemplo n.º 11
0
        /// <summary>
        /// Method to return current date and year Id
        /// </summary>
        /// <returns>Current date details</returns>
        public CurrentDateDetails GetCurrentDateAndYearId()
        {
            CurrentDateDetails curDateDetails = null;
            DateTime           curDate        = TimeZoneUtility.GetCurrentTimestamp().Date;
            var curYear = yearRepository.GetAll().Where(x => x.StartDate <= curDate &&
                                                        x.EndDate >= curDate).FirstOrDefault();

            if (curYear != null)
            {
                curDateDetails             = new CurrentDateDetails();
                curDateDetails.CurrentDate = curDate;
                curDateDetails.YearId      = curYear.Id;
            }
            return(curDateDetails);
        }
Ejemplo n.º 12
0
        /// <summary>
        /// Method to update a metric item
        /// </summary>
        /// <param name="metricItem">Metric item to update</param>
        /// <param name="userName">logged in user name</param>
        private void UpdateMetric(MetricItem metricItem, string userName)
        {
            int loggedInUserId = userRepository.GetAll().FirstOrDefault(
                x => x.AccountName == userName).Id;
            //get existing metric details
            var existingMetric = metricRepository.Get(metricItem.Id.Value);

            existingMetric.Name           = metricItem.Name;
            existingMetric.DataTypeId     = metricItem.DataType.Id.Value;
            existingMetric.GoalTypeId     = metricItem.GoalType.Id.Value;
            existingMetric.IsActive       = metricItem.IsActive;
            existingMetric.LastModifiedOn = TimeZoneUtility.GetCurrentTimestamp();
            existingMetric.LastModifiedBy = loggedInUserId;
            metricRepository.Save();
        }
Ejemplo n.º 13
0
 public UserBasic(int userId, string userName, string email, DateTime lastActivityDateUtc, AccountStatus accountStatus, DateTime dateCreatedUtc, DateTime lastLoginDateUtc
                  , int profileImageId, string timeZoneInfoId, IEnumerable <string> userRoles)
 {
     this.IsAnonymous         = false;
     this.UserId              = userId;
     this.UserName            = userName;
     this.LastActivityDateUtc = lastActivityDateUtc;
     this.AccountStatus       = accountStatus;
     this.DateCreatedUtc      = dateCreatedUtc;
     this.Email            = email;
     this.LastLoginDateUtc = lastLoginDateUtc;
     this.ProfileImageId   = profileImageId;
     this.TimeZoneInfoId   = (timeZoneInfoId ?? TimeZoneUtility.GetGMTStandardTimeZone().Id);
     this.UserRoles        = new HashSet <string>(userRoles ?? new HashSet <string>());
 }
Ejemplo n.º 14
0
        /// <summary>
        /// Method to convert Target entity to target item DTO
        /// </summary>
        /// <param name="target">target entity to be converted</param>
        /// <param name="monthsList">List of months in the calendar year</param>
        /// <returns>target item DTO</returns>
        public static TargetItem ConvertTargetToTargetItemDTO(Target target,
                                                              List <MonthItem> monthsList)
        {
            var currentDate = TimeZoneUtility.GetCurrentTimestamp();
            var targetItem  = new TargetItem()
            {
                Id                              = target.Id,
                KPIId                           = target.KPIId,
                ScorecardId                     = target.ScorecardId,
                CalendarYearId                  = target.CalendarYearId,
                MetricId                        = target.Metric.Id,
                MetricName                      = target.Metric.Name,
                MetricType                      = target.MetricType,
                MetricDataTypeId                = target.Metric.DataTypeId,
                EffectiveStartDate              = target.EffectiveStartDate,
                EffectiveEndDate                = target.EffectiveEndDate,
                CascadeFromParent               = target.CascadeFromParent,
                IsCascaded                      = target.IsCascaded,
                TargetEntryMethodId             = target.TargetEntryMethodId,
                IsStretchGoalEnabled            = target.IsStretchGoalEnabled,
                GraphPlottingMethodId           = target.GraphPlottingMethodId,
                MTDPerformanceTrackingMethodId  = target.MTDPerformanceTrackingMethodId,
                CascadedMetricsTrackingMethodId = target.CascadedMetricsTrackingMethodId,
                TrackingMethodId                = target.TrackingMethodId,
                AnnualTarget                    = target.AnnualTarget,
                MonthlyTargets                  = target.MonthlyTargets
                                                  .Select(m => ConvertMonthlyTargetToMonthlyTargetItemDTO(m,
                                                                                                          monthsList.FirstOrDefault(x => x.Id == m.Month))).ToList()
            };

            // Fill the remaining months with empty goal values
            foreach (var monthItem in monthsList)
            {
                if (!targetItem.MonthlyTargets.Any(x => x.Month.Id == monthItem.Id))
                {
                    targetItem.MonthlyTargets.Add(new MonthlyTargetItem()
                    {
                        Month       = monthItem,
                        IsPastMonth = (monthItem.Id < (currentDate.Month - 1) && monthItem.Year == currentDate.Year) || monthItem.Year < currentDate.Year
                    });
                }
            }

            // Sort the monthly targets by year and month.
            targetItem.MonthlyTargets = targetItem.MonthlyTargets.OrderBy(x => x.Month.Year).
                                        ThenBy(x => x.Month.Id).ToList();
            return(targetItem);
        }
Ejemplo n.º 15
0
        private TimeSpan GetDailyDueTime()
        {
            DateTime now, firstExecution;

            switch (this.DailyExecutionDateTimeKind)
            {
            case DateTimeKind.Local:
                #region DateTimeKind.Local
                now = TimeZoneUtility.ConvertUTCDateToLocalizedDate(DateTime.UtcNow, this.DailyLocalizedExecutionTimeZoneInfo);

                firstExecution = new DateTime(now.Year, now.Month, now.Day
                                              , this.DailyLocalizedExecutionTime.Hour
                                              , this.DailyLocalizedExecutionTime.Minute
                                              , this.DailyLocalizedExecutionTime.Second
                                              , this.DailyLocalizedExecutionTime.Millisecond);

                if (firstExecution < now)
                {
                    firstExecution = firstExecution.AddDays(1);
                }

                return((TimeSpan)(TimeZoneUtility.ConvertUTCDateToLocalizedDate(firstExecution, this.DailyLocalizedExecutionTimeZoneInfo)
                                  - now));

                #endregion

            case DateTimeKind.Utc:
                #region DateTimeKind.Utc
                now = DateTime.UtcNow;

                firstExecution = new DateTime(now.Year, now.Month, now.Day
                                              , this.DailyUTCExecutionTime.Hour
                                              , this.DailyUTCExecutionTime.Minute
                                              , this.DailyUTCExecutionTime.Second
                                              , this.DailyUTCExecutionTime.Millisecond);

                if (firstExecution < now)
                {
                    firstExecution = firstExecution.AddDays(1);
                }

                return((TimeSpan)(firstExecution - now));

                #endregion

            default: throw new NotSupportedException();
            }
        }
Ejemplo n.º 16
0
        /// <summary>
        /// Convert MonthlyTargetItem data structure to MonthlyTarget
        /// </summary>
        /// <param name="monthlyTarget">Input MonthlyTargetItem</param>
        /// <param name="loggedInUserId">Logged In UserId</param>
        /// <returns>MonthlyTarget DS</returns>
        public static MonthlyTarget ConvertMonthlyTargetItemToMonthlyTargetEntity(
            MonthlyTargetItem monthlyTarget, int loggedInUserId)
        {
            DateTime      curTimestamp = TimeZoneUtility.GetCurrentTimestamp();
            MonthlyTarget mthlyTarget  = new MonthlyTarget();

            mthlyTarget.Month            = monthlyTarget.Month.Id;
            mthlyTarget.MaxGoalValue     = monthlyTarget.GoalValue;
            mthlyTarget.DailyRate        = monthlyTarget.DailyRateValue;
            mthlyTarget.StretchGoalValue = monthlyTarget.StretchGoalValue;
            mthlyTarget.CreatedOn        = curTimestamp;
            mthlyTarget.LastModifiedOn   = curTimestamp;
            mthlyTarget.CreatedBy        = loggedInUserId; //Need to update with logged in user in future
            mthlyTarget.LastModifiedBy   = loggedInUserId; //Need to update with logged in user in future
            return(mthlyTarget);
        }
Ejemplo n.º 17
0
        /// <summary>
        /// Method to update monthly actual entry
        /// </summary>
        /// <param name="actualRequest">daily actual request</param>
        /// <param name="goalTypeId">metric goal type id</param>
        /// <param name="userName">logged in user name</param>
        public virtual void UpdateMonthlyActual(ActualItem actualRequest, int goalTypeId, string userName)
        {
            //get logged in user id
            int loggedInUserId = userRepository.GetAll().FirstOrDefault(
                x => x.AccountName == userName)?.Id ?? 0;
            var monthlyActual = monthlyActualRepository.Get(actualRequest.Id.Value);

            monthlyActual.ActualValue = actualRequest.ActualValue;
            monthlyActual.Status      = TargetActualComparer.GetActualStatus(actualRequest.GoalValue,
                                                                             actualRequest.ActualValue, goalTypeId);
            monthlyActual.LastModifiedOn = TimeZoneUtility.GetCurrentTimestamp();
            monthlyActual.LastModifiedBy = loggedInUserId;
            monthlyActual.MonthlyActualHistory.Add(
                ActualConverters.ConvertMonthlyActualToMonthlyActualHistory(monthlyActual));
            monthlyActualRepository.Save();
        }
Ejemplo n.º 18
0
        /// <summary>
        /// Update Holiday Mappings
        /// </summary>
        /// <param name="request"></param>
        /// <param name="userName"></param>
        private void UpdateHolidayMapping(HolidayPatternInfoRequest request, string userName)
        {
            var loggedInUserId = userRepository.GetAll().FirstOrDefault(x =>
                                                                        x.AccountName == userName).Id;
            var holidayPattern = holidayPatternRepository.Get(request.HolidayPatternId);

            var removedHolidays = holidayPattern.Holidays.Where(m =>
                                                                m.IsActive &&
                                                                !request.Holidays.Contains(m.Date));

            foreach (var holiday in removedHolidays)
            {
                holiday.IsActive       = false;
                holiday.LastModifiedBy = loggedInUserId;
                holiday.LastModifiedOn = TimeZoneUtility.GetCurrentTimestamp();
            }
            var reactivatedHolidays = holidayPattern.Holidays.Where(m =>
                                                                    !m.IsActive &&
                                                                    request.Holidays.Contains(m.Date));

            foreach (var holiday in reactivatedHolidays)
            {
                holiday.IsActive       = true;
                holiday.LastModifiedBy = loggedInUserId;
                holiday.LastModifiedOn = TimeZoneUtility.GetCurrentTimestamp();
            }

            var addedHolidays = request.Holidays.Where(x =>
                                                       !holidayPattern.Holidays.Select(m => m.Date).Contains(x));

            foreach (var holiday in addedHolidays)
            {
                holidayPattern.Holidays.Add(new HolidayPatternInfo
                {
                    HolidayPatternId = request.HolidayPatternId,
                    Date             = holiday.Date,
                    IsActive         = true,
                    CreatedBy        = loggedInUserId,
                    CreatedOn        = TimeZoneUtility.GetCurrentTimestamp(),
                    LastModifiedBy   = loggedInUserId,
                    LastModifiedOn   = TimeZoneUtility.GetCurrentTimestamp()
                });
            }

            holidayPatternRepository.AddOrUpdate(holidayPattern);
            holidayPatternRepository.Save();
        }
Ejemplo n.º 19
0
        /// <summary>
        /// Add news Holiday Pattern
        /// </summary>
        /// <param name="requestItem"></param>
        /// <param name="userName"></param>
        private void AddHolidayPattern(HolidayPatternItem requestItem, string userName)
        {
            var loggedInUserId = userRepository.GetAll().FirstOrDefault(x =>
                                                                        x.AccountName == userName).Id;
            var newPattern = new HolidayPattern
            {
                Name           = requestItem.Name,
                IsActive       = requestItem.IsActive,
                CreatedBy      = loggedInUserId,
                CreatedOn      = TimeZoneUtility.GetCurrentTimestamp(),
                LastModifiedBy = loggedInUserId,
                LastModifiedOn = TimeZoneUtility.GetCurrentTimestamp()
            };

            holidayPatternRepository.AddOrUpdate(newPattern);
            holidayPatternRepository.Save();
        }
Ejemplo n.º 20
0
        public double?GetNumberOfDaysWithOutRecordables(Scorecard scorecard)
        {
            bool isNumberOfDaysWithOutRecordablesEnabled = Convert.ToBoolean(
                ConfigurationManager.AppSettings[AppSettingsKeys.
                                                 EnableNumberOfDaysWithoutRecordables]);

            if (isNumberOfDaysWithOutRecordablesEnabled && scorecard.Recordables != null && scorecard.Recordables.Any(x => x.IsActive))
            {
                Recordable recordable = scorecard.Recordables.Where(x => x.IsActive)
                                        .OrderByDescending(x => x.RecordableDate).First();

                DateTime currentDate = TimeZoneUtility.GetCurrentTimestamp().Date;
                double   numberofDaysWithoutRecordables = (currentDate - recordable.RecordableDate).TotalDays;
                return(numberofDaysWithoutRecordables);
            }

            return(null);
        }
Ejemplo n.º 21
0
        /// <summary>
        /// Retrieves all counter measures related to a KPI of a particular scorecard for
        /// an year
        /// </summary>
        /// <param name="scorecardId">Scorecard Identifier</param>
        /// <param name="kpiId">KPI Identifier</param>
        /// <returns>All Counter Measures related to the KPI</returns>
        public IEnumerable <CounterMeasureItem> GetCounterMeasures(int scorecardId, int kpiId,
                                                                   bool isShowClosed)
        {
            DateTime currentDate = TimeZoneUtility.GetCurrentTimestamp().Date;

            // get all counter measures except the confirmed counter measure if isShowClosed is false
            // otherwise get all counter measures
            var counterMeasures = counterMeasureRepository.GetAll()
                                  .Where(x => x.ScorecardId == scorecardId &&
                                         x.KPIId == kpiId &&
                                         x.CounterMeasureStatusId != (isShowClosed ?
                                                                      -1 : Constants.CounterMeasureStatusConfirmed))
                                  .OrderByDescending(x => x.CreatedOn)
                                  .ToList().Select(x => CounterMeasureConverters.
                                                   ConvertCounterMeasureToCounterMeasureItemDTO(x));

            return(counterMeasures.ToList());
        }
Ejemplo n.º 22
0
        /// <summary>
        /// Method to get monthly goal
        /// </summary>
        /// <param name="targetId">target id</param>
        /// <param name="month">month</param>
        /// <returns>monthly target value</returns>
        public virtual decimal?GetMonthlyGoal(int targetId, int month)
        {
            var target = targetRepository.Get(targetId);

            if (target == null || !target.IsActive)
            {
                throw new NDMSBusinessException(Constants.TargetNotFound);
            }

            // logic to find out legend data
            DateTime currentDate = TimeZoneUtility.GetCurrentTimestamp();
            int      targetYear  = target.CalendarYear.StartDate.Year;
            // check whether cascaded metrics tracking method is rolled up targets
            bool isRolledUpTarget = IsRolledUpTargetsForMonth(target, month);
            var  monthlyTarget    = target.MonthlyTargets.FirstOrDefault(x => x.Month == month);

            return(isRolledUpTarget ? monthlyTarget?.RolledUpGoalValue : monthlyTarget?.MaxGoalValue);
        }
Ejemplo n.º 23
0
        /// <summary>
        /// Deletes the recordable details for the given month.
        /// </summary>
        /// <param name="target">The target.</param>
        /// <param name="recordableDate">The recordable date.</param>
        /// <param name="loggedInUserId">The logged in user identifier.</param>
        private void DeleteRecordablesOfMonth(Target target, DateTime recordableDate, int loggedInUserId)
        {
            var scorecardRecordable = recordableRepository.GetAll()
                                      .Where(x => x.ScorecardId == target.ScorecardId &&
                                             x.RecordableDate.Month == recordableDate.Month &&
                                             x.RecordableDate.Year == recordableDate.Year &&
                                             !x.IsManual && x.IsActive);

            if (scorecardRecordable != null)
            {
                foreach (var recordable in scorecardRecordable)
                {
                    recordable.IsActive       = false;
                    recordable.LastModifiedBy = loggedInUserId;
                    recordable.LastModifiedOn = TimeZoneUtility.GetCurrentTimestamp();
                    recordableRepository.AddOrUpdate(recordable);
                }
            }
        }
Ejemplo n.º 24
0
        /// <summary>
        /// Add a new counter measure for a metric which belongs to a score card and KPI
        /// </summary>
        /// <param name="counterMeasureRequest">new counter measure entry</param>
        /// <param name="userName">Logged in user name</param>
        public void AddCounterMeasure(CounterMeasureAddRequest counterMeasureRequest,
                                      string userName)
        {
            ValidateCounterMeasureDueDate(counterMeasureRequest.DueDate);
            // Get logged in user id
            int loggedInUserId = userRepository.GetAll().FirstOrDefault(
                x => x.AccountName == userName).Id;

            // If the assigned user is not added to NDMS users table, add it here
            var assignedUserIds = userRepository.AddADUsersToNDMS(new List <string>()
            {
                counterMeasureRequest.AssignedTo
            });

            var counterMeasure = new CounterMeasure()
            {
                ScorecardId              = counterMeasureRequest.ScorecardId.Value,
                KPIId                    = counterMeasureRequest.KPIId.Value,
                MetricId                 = counterMeasureRequest.MetricId.Value,
                Issue                    = counterMeasureRequest.Issue,
                Action                   = counterMeasureRequest.Action,
                AssignedTo               = assignedUserIds.First(),
                DueDate                  = counterMeasureRequest.DueDate,
                CounterMeasureStatusId   = counterMeasureRequest.CounterMeasureStatusId.Value,
                CounterMeasurePriorityId = counterMeasureRequest.CounterMeasurePriorityId != null ?
                                           counterMeasureRequest.CounterMeasurePriorityId.Value:
                                           (int?)null,
                CreatedBy              = loggedInUserId,
                LastModifiedBy         = loggedInUserId,
                CreatedOn              = TimeZoneUtility.GetCurrentTimestamp(),
                LastModifiedOn         = TimeZoneUtility.GetCurrentTimestamp(),
                CounterMeasureComments = !string.IsNullOrEmpty(counterMeasureRequest.Comment) ?
                                         new List <CounterMeasureComment>()
                {
                    CounterMeasureConverters.
                    ConvertCommentToCounterMeasureComment(counterMeasureRequest.Comment,
                                                          loggedInUserId)
                } : null
            };

            counterMeasureRepository.AddOrUpdate(counterMeasure);
            counterMeasureRepository.Save();
        }
Ejemplo n.º 25
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();
        }
Ejemplo n.º 26
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();
        }
        public void Test_CreateUser()
        {
            IApplicationSettings applicationSettings = Workmate.Components.InstanceContainer.ApplicationSettings;

            WorkmateRoleProvider       roleProvider       = new WorkmateRoleProvider();
            WorkmateMembershipProvider membershipProvider = new WorkmateMembershipProvider();

            DummyUser user = this.DummyDataManager.GetDummy();

            string        firstName     = user.Firstname;
            string        lastName      = user.Surname;
            string        password      = "******";
            AccountStatus accountStatus = AccountStatus.Valid;
            TimeZoneInfo  timeZoneInfo  = TimeZoneUtility.GetGMTStandardTimeZone();

            IUserBasic userBasic = new UserBasic(user.Email, user.Email, 1)
            {
                AccountStatus = accountStatus,
                TimeZoneInfo  = timeZoneInfo
            };

            Guid            uniqueId;
            List <UserRole> userRoles = new List <UserRole>()
            {
                UserRole.SystemAdministrator, UserRole.Registered
            };
            UserCreateStatus userCreateStatus = membershipProvider.CreateUser(ref userBasic, password, userRoles, UserNameDisplayMode.FullName
                                                                              , firstName, lastName
                                                                              , DebugUtility.GetRandomEnum <Workmate.Components.Contracts.Membership.Gender>(this.Random)
                                                                              , out uniqueId, this.Application.ApplicationId).Status;

            Assert.AreEqual(UserCreateStatus.Success, userCreateStatus);
            Assert.Greater(userBasic.UserId, 0);

            userBasic = membershipProvider.GetUserBasic(userBasic.UserId, false);

            Assert.AreEqual(user.Email, userBasic.UserName);
            Assert.AreEqual(user.Email, userBasic.Email);
            Assert.AreEqual(accountStatus, userBasic.AccountStatus);
            Assert.AreEqual(timeZoneInfo.Id, userBasic.TimeZoneInfoId);
        }
Ejemplo n.º 28
0
        /// <summary>
        /// Method to convert monthly target entity to monthly target item DTO
        /// </summary>
        /// <param name="monthlyTarget">MonthlyTarget Entity</param>
        /// <param name="monthItem">MonthItem DTO</param>
        /// <returns></returns>
        public static MonthlyTargetItem ConvertMonthlyTargetToMonthlyTargetItemDTO
            (MonthlyTarget monthlyTarget, MonthItem monthItem)
        {
            var currentDate = TimeZoneUtility.GetCurrentTimestamp();

            var monthlyTargetItem = new MonthlyTargetItem()
            {
                Id                     = monthlyTarget.Id,
                Month                  = monthItem,
                GoalValue              = monthlyTarget.MaxGoalValue,
                DailyRateValue         = monthlyTarget.DailyRate,
                StretchGoalValue       = monthlyTarget.StretchGoalValue,
                HasManualTarget        = monthlyTarget.DailyTargets.Any(x => x.IsManual),
                HasRolledUpDailyTarget = monthlyTarget.DailyTargets.Any(x => x.RolledUpGoalValue != null),
                HasDailyTarget         = monthlyTarget.DailyTargets.Any(x => x.MaxGoalValue != null),
                IsPastMonth            = (monthItem.Id < (currentDate.Month - 1) && monthItem.Year == currentDate.Year) || monthItem.Year < currentDate.Year,
                RolledupGoalValue      = monthlyTarget.RolledUpGoalValue
            };

            return(monthlyTargetItem);
        }
Ejemplo n.º 29
0
        public void Test_DailyExecutionTimeWithDaylightSavingAdjustment()
        {
            TimeZoneInfo timeZoneInfo = TimeZoneUtility.GetTimeZoneInfo("GMT Standard Time");

            List <DateTime> futureDates = new List <DateTime>()
            {
                new DateTime(2011, 3, 24, 23, 0, 0, DateTimeKind.Utc),
                new DateTime(2011, 3, 25, 23, 0, 0, DateTimeKind.Utc),
                new DateTime(2011, 3, 26, 23, 0, 0, DateTimeKind.Utc),
                new DateTime(2011, 3, 27, 23, 0, 0, DateTimeKind.Utc),
                new DateTime(2011, 3, 28, 23, 0, 0, DateTimeKind.Utc),
                new DateTime(2011, 3, 29, 23, 0, 0, DateTimeKind.Utc)
            };

            DateTime nowLocal = TimeZoneUtility.ConvertUTCDateToLocalizedDate(futureDates[0], timeZoneInfo).AddDays(-1);

            foreach (DateTime fd in futureDates)
            {
                Trace.WriteLine((TimeZoneUtility.ConvertUTCDateToLocalizedDate(fd, timeZoneInfo) - nowLocal).ToString() + "\n");
                nowLocal = (TimeZoneUtility.ConvertUTCDateToLocalizedDate(fd, timeZoneInfo));
            }
        }
Ejemplo n.º 30
0
        /// <summary>
        /// Convert DailyTargetItem DS to DailyTarget
        /// </summary>
        /// <param name="dailyTarget">Input DailyTargetItem</param>
        /// <param name="monthlyTarget">Corresponding monthly target</param>
        /// <param name="loggedInUserId">Logged In UserId</param>
        /// <returns>DailyTarget DS</returns>
        public static DailyTarget ConvertDailyTargetItemToDailyTargetEntity(
            DailyTargetItem dailyTarget,
            MonthlyTarget monthlyTarget,
            int loggedInUserId)
        {
            DateTime    curTimestamp = TimeZoneUtility.GetCurrentTimestamp();
            DailyTarget daily        = new DailyTarget();

            daily.MonthlyTarget      = monthlyTarget;
            daily.Day                = dailyTarget.Day;
            daily.MaxGoalValue       = dailyTarget.GoalValue;
            daily.IsManual           = dailyTarget.IsManual;
            daily.CreatedOn          = curTimestamp;
            daily.LastModifiedOn     = curTimestamp;
            daily.CreatedBy          = loggedInUserId; //Need to update with logged in user in future
            daily.LastModifiedBy     = loggedInUserId; //Need to update with logged in user in future
            daily.DailyTargetHistory = new List <DailyTargetHistory>()
            {
                ConvertDailyTargetToDailyTargetHistory(daily)
            };
            return(daily);
        }