private static bool ValidateCourseCodeExists(ITrainingCourseRepository repository, string courseCode, StringBuilder errorMessage, SPWeb web) { bool courseExists = false; TrainingCourse course = new TrainingCourse(); course = repository.Get(courseCode, web); if (course != null) { courseExists = true; errorMessage.AppendLine("The Course Code is already in use."); } return(courseExists); }
public void RenderCourseRegistrationView(SPWeb web, string loginName) { if (this._view.QueryString.AllKeys.Contains("ID")) { int courseId; TrainingCourse course = null; Registration registration = null; bool success = false; SPUser user = null; Int32.TryParse(this._view.QueryString["ID"], out courseId); this._view.HeaderTitle = "Course Registration"; this._view.SiteLink = web.Url; success = GetCourseUserRegistration(web, courseId, out course, out registration, out user, loginName); this._view.ShowConfirmationControls = success; if (course != null) { this._view.PageTitle = string.Format("Course Registration - {0}", course.Code); this._view.HeaderSubtitle = course.Code; } if (success) { this._view.ContentMessage = string.Format("Would you like to register for course: {0}?", course.Code); } } else { this._view.HeaderTitle = "Course Registration"; this._view.PageTitle = "Course Registration - New"; this._view.HeaderSubtitle = "New"; this._view.ContentMessage = "Which course would you like to register for?"; this._view.SiteLink = web.Url; ITrainingCourseRepository trainingCourseRepository = ServiceLocator.GetInstance().Get <ITrainingCourseRepository>(); this._view.Courses = trainingCourseRepository.Get(web); this._view.ShowCourseSelectionControls = true; this._view.ShowConfirmationControls = true; } }
/// <summary> /// Populates the SPWorkflowTaskProperties with Title and AssignedTo data. /// </summary> /// <param name="taskProperties">SPWorkflowTaskProperties to populate.</param> /// <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 PopulateManagerApprovalTaskProperties(SPWorkflowTaskProperties taskProperties, SPWeb web, SPListItem workflowItem) { IHRManager hrManager = serviceLocator.Get <IHRManager>(); 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 and manager related to this registration. SPUser user = GetSPUser(web, registration.UserId); SPUser manager = GetSPUser(web, hrManager.GetManager(user.LoginName)); taskProperties.AssignedTo = manager.LoginName; taskProperties.Title = String.Format("Approve new registration request from {0} for {1}.", user.Name, trainingCourse.Code); }
/// <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); }
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); }
/// <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 ActionResult <CommonResponeModel> GetAll() { Data = trainingCourseRepository.Get().ToList(); Result = new SuccessResultFactory().Factory(ActionType.Select); return(GetCommonRespone()); }