Example #1
0
        /// <summary>
        /// Saves the reward information.
        /// </summary>
        /// <param name="rewardInfo">The reward information.</param>
        /// <returns></returns>
        /// <exception cref="ArgumentNullException">rewardInfo</exception>
        public string SaveRewardInfo(IRewardView rewardInfo)
        {
            if (rewardInfo == null)
            {
                throw new ArgumentNullException(nameof(rewardInfo));
            }

            var result = string.Empty;

            var newRecord = new Reward
            {
                RewardName  = rewardInfo.RewardName,
                CompanyId   = rewardInfo.CompanyId,
                DateCreated = DateTime.UtcNow,
                Amount      = rewardInfo.Amount,
                IsActive    = true
            };

            try
            {
                using (
                    var dbContext = (HRMSEntities)this.dbContextFactory.GetDbContext(ObjectContextType.HRMS))
                {
                    dbContext.Rewards.Add(newRecord);
                    dbContext.SaveChanges();
                }
            }
            catch (Exception e)
            {
                result = string.Format("Save Reward info - {0}, {1}", e.Message,
                                       e.InnerException != null ? e.InnerException.Message : "");
            }

            return(result);
        }
Example #2
0
        /// <summary>
        /// Saves the edit reward information.
        /// </summary>
        /// <param name="rewardInfo">The reward information.</param>
        /// <returns></returns>
        /// <exception cref="ArgumentNullException">rewardInfo</exception>
        public string SaveEditRewardInfo(IRewardView rewardInfo)
        {
            if (rewardInfo == null)
            {
                throw new ArgumentNullException(nameof(rewardInfo));
            }

            string result = string.Empty;

            try
            {
                using (
                    var dbContext = (HRMSEntities)this.dbContextFactory.GetDbContext(ObjectContextType.HRMS))
                {
                    var modelInfo = dbContext.Rewards.SingleOrDefault(p => p.RewardId == rewardInfo.RewardId);

                    modelInfo.RewardName = rewardInfo.RewardName;
                    modelInfo.Amount     = rewardInfo.Amount;

                    dbContext.SaveChanges();
                }
            }
            catch (Exception e)
            {
                result = string.Format("Save Edit Reward info - {0}, {1}", e.Message,
                                       e.InnerException != null ? e.InnerException.Message : "");
            }

            return(result);
        }