/// <summary> /// Updates the grade information. /// </summary> /// <param name="gradeInfo">The grade information.</param> /// <returns></returns> /// <exception cref="ArgumentNullException">gradeInfo</exception> public string UpdateGradeInfo(IGradeView gradeInfo) { if (gradeInfo == null) { throw new ArgumentNullException(nameof(gradeInfo)); } var result = string.Empty; try { using ( var dbContext = (HRMSEntities)this.dbContextFactory.GetDbContext(ObjectContextType.HRMS)) { var gradeData = dbContext.Grades.SingleOrDefault(m => m.GradeId.Equals(gradeInfo.GradeId)); gradeData.GradeName = gradeInfo.GradeName; gradeData.GradeDescription = gradeInfo.GradeDescription; gradeData.AnnualLeaveDuration = gradeInfo.AnnualLeaveDuration; gradeData.DateModified = DateTime.UtcNow; dbContext.SaveChanges(); } } catch (Exception e) { result = string.Format("Update Grade - {0} , {1}", e.Message, e.InnerException != null ? e.InnerException.Message : ""); } return(result); }
/// <summary> /// Saves the grade information. /// </summary> /// <param name="gradeInfo">The grade information.</param> /// <returns></returns> /// <exception cref="ArgumentNullException">gradeInfo</exception> public string SaveGradeInfo(IGradeView gradeInfo) { if (gradeInfo == null) { throw new ArgumentNullException(nameof(gradeInfo)); } var result = string.Empty; var newRecord = new Grade { GradeName = gradeInfo.GradeName, GradeDescription = gradeInfo.GradeDescription, AnnualLeaveDuration = gradeInfo.AnnualLeaveDuration, IsActive = true, CompanyId = gradeInfo.CompanyId, DateCreated = DateTime.UtcNow, }; try { using ( var dbContext = (HRMSEntities)this.dbContextFactory.GetDbContext(ObjectContextType.HRMS)) { dbContext.Grades.Add(newRecord); dbContext.SaveChanges(); } } catch (Exception e) { result = string.Format("SaveRegistrationInfo - {0} , {1}", e.Message, e.InnerException != null ? e.InnerException.Message : ""); } return(result); }