public TrainingCourseEmployeeSaveChangeValidator(IEmployeeRepository employeeRepository, ITrainingCourseRepository trainingCourseRepository) { this._employeeRepository = employeeRepository; this._trainingCourseRepository = trainingCourseRepository; RuleFor(x => x.Id).NotEmpty().WithMessage(CommonMessageGlobal.Require("Id")) .GreaterThanOrEqualTo(0).WithMessage(CommonMessageGlobal.GreaterThanOrEqual("Id", 0)); RuleFor(x => x.EmployeeCode).NotEmpty().WithMessage(CommonMessageGlobal.Require("Mã nhân viên")) .MinimumLength(2).WithMessage(CommonMessageGlobal.Minimum("Mã nhân viên", 2)) .MaximumLength(20).WithMessage(CommonMessageGlobal.Maximum("Mã nhân viên", 20)) .Must(IsValidEmployeeCode).WithMessage(CommonMessageGlobal.Invalid("Mã nhân viên")); RuleFor(x => x.TrainingCourseCode).NotEmpty().WithMessage(CommonMessageGlobal.Require("Mã ca làm việc")) .MinimumLength(2).WithMessage(CommonMessageGlobal.Minimum("Mã ca làm việc", 2)) .MaximumLength(20).WithMessage(CommonMessageGlobal.Maximum("Mã ca làm việc", 20)) .Must(IsValidCourseCode).WithMessage(CommonMessageGlobal.Invalid("Mã ca làm việc")); }
/// <summary> /// Ensures the course related to the request is valid. /// </summary> /// <param name="web">The SPWeb in the current context.</param> /// <param name="view">The view to render content.</param> /// <param name="courseId">The ID of the training course to register for.</param> /// <param name="course">The course to populate.</param> /// <returns>Success flag.</returns> private static bool GetCourse(SPWeb web, ICourseRegistrationView view, int courseId, out TrainingCourse course) { bool success = false; ITrainingCourseRepository trainingCourseRepository = ServiceLocator.GetInstance().Get <ITrainingCourseRepository>(); course = trainingCourseRepository.Get(courseId, web); if (course != null) { success = true; } else { view.ContentMessage = "The Course selected was not a valid."; } return(success); }
public TrainingCourseUpdateValidator(ITrainingCourseRepository trainingCourseRepository) { this._trainingCourseRepository = trainingCourseRepository; RuleFor(x => x.Id).NotEmpty().WithMessage(CommonMessageGlobal.Require("Id")) .GreaterThan(0).WithMessage(CommonMessageGlobal.GreaterThan("Id", 0)); RuleFor(x => x.Code).MinimumLength(2).WithMessage(CommonMessageGlobal.Minimum("Mã khóa đào tạo", 2)) .MaximumLength(20).WithMessage(CommonMessageGlobal.Maximum("Mã khóa đào tạo", 20)); RuleFor(x => x.Name).NotEmpty().WithMessage(CommonMessageGlobal.Require("Mã khóa đào tạo")) .MinimumLength(2).WithMessage(CommonMessageGlobal.Minimum("Mã khóa đào tạo", 2)) .MaximumLength(256).WithMessage(CommonMessageGlobal.Maximum("Mã khóa đào tạo", 256)); RuleFor(x => x.ParentCode).MinimumLength(2).WithMessage(CommonMessageGlobal.Minimum("Mã khóa đào tạo cha", 2)) .MaximumLength(20).WithMessage(CommonMessageGlobal.Maximum("Mã khóa đào tạo cha", 20)) .Must(IsValidParentCode).WithMessage(CommonMessageGlobal.Invalid("Mã khóa đào tạo cha")); }
private static bool GetCourseAndUser(SPWeb web, IRegistrationApprovalView view, Registration registration, out TrainingCourse course, out SPUser user) { ITrainingCourseRepository trainingCourseRepository = ServiceLocator.GetInstance().Get <ITrainingCourseRepository>(); course = trainingCourseRepository.Get(registration.CourseId, web); if (course == null) { view.Message = "The Course associated with the selected Approval Task is not valid."; user = null; return(false); } user = GetSPUser(web, registration.UserId.ToString()); if (user == null) { view.Message = "The Employee associated with the selected Approval Task is not valid."; return(false); } return(true); }
public override void ItemUpdating(SPItemEventProperties properties) { bool isValid = true; StringBuilder errorMessage = new StringBuilder(); string title = string.Empty; string code = string.Empty; DateTime enrollmentDate = DateTime.MinValue; DateTime startDate = DateTime.MinValue; DateTime endDate = DateTime.MinValue; float cost = 0; using (SPWeb web = properties.OpenWeb()) { ITrainingCourseRepository repository = ServiceLocator.GetInstance().Get <ITrainingCourseRepository>(); Initalize(properties.AfterProperties, repository, web, out title, out code, out enrollmentDate, out startDate, out endDate, out cost); if (properties.ListItem[repository.GetFieldName(new Guid(Fields.TrainingCourseCode), web)].ToString() != code) { if (ValidateCourseCodeExists(repository, code, errorMessage, web)) { isValid = false; } } } isValid = isValid & ValidateCourseCode(code, errorMessage); isValid = isValid & ValidateStartDate(enrollmentDate, startDate, errorMessage); isValid = isValid & ValidateEndDate(startDate, endDate, errorMessage); isValid = isValid & ValidateCourseCost(cost, errorMessage); //if any of the rules fail, set an error message and set the //Cancel property to true to instruct SharePoint to redirect to //standard error page. if (!isValid) { properties.ErrorMessage = errorMessage.ToString(); properties.Cancel = true; } }
public override void ItemAdding(SPItemEventProperties properties) { bool isValid = true; StringBuilder errorMessage = new StringBuilder(); string title = string.Empty; string code = string.Empty; DateTime enrollmentDate = DateTime.MinValue; DateTime startDate = DateTime.MinValue; DateTime endDate = DateTime.MinValue; float cost = 0; //A web is required to retrieve Field names for iterating through ListItem collection //in the SPItemEventProperties as well as retrieveing existing items in the TrainingCourses list. using (SPWeb web = properties.OpenWeb()) { ITrainingCourseRepository repository = ServiceLocator.GetInstance().Get <ITrainingCourseRepository>(); Initalize(properties.AfterProperties, repository, web, out title, out code, out enrollmentDate, out startDate, out endDate, out cost); if (ValidateCourseCodeExists(repository, code, errorMessage, web)) { isValid = false; } } isValid = isValid & ValidateCourseCode(code, errorMessage); isValid = isValid & ValidateEnrollmentDate(enrollmentDate, errorMessage); isValid = isValid & ValidateStartDate(enrollmentDate, startDate, errorMessage); isValid = isValid & ValidateEndDate(startDate, endDate, errorMessage); isValid = isValid & ValidateCourseCost(cost, errorMessage); //if any of the rules fail, set an error message and set the //Cancel property to true to instruct SharePoint to redirect to //standard error page. if (!isValid) { properties.ErrorMessage = errorMessage.ToString(); properties.Cancel = true; } }
/// <summary> /// Charges the Accounting service for the cost of the course registration. /// </summary> /// <param name="web">The SPWeb in the current workflow context.</param> /// <param name="workflowItem">The SPListItem that the workflow instance is associated with.</param> public void ChargeAccounting(SPWeb web, SPListItem workflowItem) { IHRManager hrManager = serviceLocator.Get <IHRManager>(); IAccountingManager accountingManager = serviceLocator.Get <IAccountingManager>(); IRegistrationRepository registrationRepository = serviceLocator.Get <IRegistrationRepository>(); ITrainingCourseRepository trainingCourseRepository = serviceLocator.Get <ITrainingCourseRepository>(); //get registration and training course related to this task. Registration registration = registrationRepository.Get(workflowItem.ID, web); TrainingCourse trainingCourse = trainingCourseRepository.Get(registration.CourseId, web); //get the user related to this registration SPUser user = GetSPUser(web, registration.UserId); //construct the transaction related to this approved registration Transaction tran = new Transaction(); tran.Amount = trainingCourse.Cost; tran.CostCenter = hrManager.GetCostCenter(user.LoginName); tran.Bucket = trainingBucketString; tran.Description = String.Format("{0} training course registration by {1}.", trainingCourse.Title, user.Name); accountingManager.SaveTransaction(tran); }
public TrainingCourseService(ITrainingCourseRepository trainingCourseRepository) : base(trainingCourseRepository) { _TrainingCourseRepository = (ITrainingCourseRepository)trainingCourseRepository; }