コード例 #1
0
        /// <summary>
        /// Saves the level information.
        /// </summary>
        /// <param name="levelInfo">The level information.</param>
        /// <returns></returns>
        /// <exception cref="ArgumentNullException">levelInfo</exception>
        public string SaveLevelInfo(ILevelView levelInfo)
        {
            if (levelInfo == null)
            {
                throw new ArgumentNullException(nameof(levelInfo));
            }

            var result = string.Empty;

            var newRecord = new Level
            {
                LevelName        = levelInfo.LevelName,
                LevelDescription = levelInfo.LevelDescription,
                CompanyId        = levelInfo.CompanyId,
                DateCreated      = DateTime.UtcNow,
                IsActive         = true,
            };

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

            return(result);
        }
コード例 #2
0
        /// <summary>
        /// Updates the level information.
        /// </summary>
        /// <param name="levelInfo">The level information.</param>
        /// <returns></returns>
        /// <exception cref="ArgumentNullException">
        /// levelInfo
        /// or
        /// levelData
        /// </exception>
        public string UpdateLevelInfo(ILevelView levelInfo)
        {
            if (levelInfo == null)
            {
                throw new ArgumentNullException(nameof(levelInfo));
            }

            var result = string.Empty;


            try
            {
                using (
                    var dbContext = (HRMSEntities)this.dbContextFactory.GetDbContext(ObjectContextType.HRMS))
                {
                    var levelData =
                        dbContext.Levels.SingleOrDefault(m => m.LevelId.Equals(levelInfo.LevelId));
                    if (levelData == null)
                    {
                        throw new ArgumentNullException(nameof(levelData));
                    }

                    levelData.LevelName        = levelInfo.LevelName;
                    levelData.LevelDescription = levelInfo.LevelDescription;
                    levelData.DateModified     = DateTime.UtcNow;


                    dbContext.SaveChanges();
                }
            }
            catch (Exception e)
            {
                result = string.Format("Update Level Information - {0} , {1}", e.Message,
                                       e.InnerException != null ? e.InnerException.Message : "");
            }

            return(result);
        }