Ejemplo n.º 1
0
        /// <summary>
        /// Adds the or update monthly targets.
        /// </summary>
        /// <param name="targetId">The target identifier.</param>
        /// <param name="monthlyTargets">The monthly targets.</param>
        /// <param name="userName">Name of the user.</param>
        public void AddOrUpdateMonthlyTargets(int targetId, IList <RollupTargetItem> monthlyTargets, string userName)
        {
            int loggedInUserId = userRepository.GetAll().FirstOrDefault(
                x => x.AccountName == userName)?.Id ?? 0;
            DateTime curTimestamp = TimeZoneUtility.GetCurrentTimestamp();

            foreach (RollupTargetItem target in monthlyTargets)
            {
                if (target.TargetId.HasValue)
                {
                    var existingMonthlyTarget = monthlyTargetRepository.Get(target.TargetId.Value);
                    existingMonthlyTarget.RolledUpGoalValue = target.RollUpValue;
                    existingMonthlyTarget.LastModifiedBy    = loggedInUserId;
                    existingMonthlyTarget.LastModifiedOn    = curTimestamp;
                    var monthlyTargetHistory = TargetConverters.ConvertMonthlyTargetToMonthlyTargetHistory(existingMonthlyTarget);
                    monthlyTargetHistory.TargetId = existingMonthlyTarget.TargetId;
                    existingMonthlyTarget.MonthlyTargetHistory.Add(monthlyTargetHistory);
                }
                else
                {
                    if (target.RollUpValue.HasValue)
                    {
                        var monthlyTarget = CreateMonthlyRollupTarget(targetId, target.TargetEntryDate.Month, loggedInUserId);
                        monthlyTarget.RolledUpGoalValue = target.RollUpValue;
                        monthlyTargetRepository.AddOrUpdate(monthlyTarget);
                    }
                }
            }

            monthlyTargetRepository.Save();
        }
Ejemplo n.º 2
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.º 3
0
        /// <summary>
        /// Creates the monthly target.
        /// </summary>
        /// <param name="targetId">The target identifier.</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 CreateMonthlyRollupTarget(int targetId, int month, int loggedInUserId)
        {
            DateTime curTimestamp  = TimeZoneUtility.GetCurrentTimestamp();
            var      monthlyTarget = new MonthlyTarget
            {
                TargetId       = targetId,
                Month          = month,
                CreatedBy      = loggedInUserId,
                CreatedOn      = curTimestamp,
                LastModifiedBy = loggedInUserId,
                LastModifiedOn = curTimestamp
            };

            var monthlyTargetHistory = TargetConverters.ConvertMonthlyTargetToMonthlyTargetHistory(monthlyTarget);

            monthlyTargetHistory.TargetId      = targetId;
            monthlyTarget.MonthlyTargetHistory = new List <MonthlyTargetHistory>
            {
                monthlyTargetHistory
            };

            return(monthlyTarget);
        }