public ActionResult Delete(SalaryReviewAnalysis a, SalaryReviewAnalysisSearchParamsModel salaryReviewAnalysisSearchParamsModel) { var referenceNumber = a.ReferenceNumber; var salaryReviewAnalysisToDelete = _salaryReviewAnalysisRepository.Queryable .Where(x => x.ReferenceNumber == referenceNumber) .FirstOrDefault(); if (salaryReviewAnalysisToDelete == null) { return(RedirectToAction("Index")); } _salaryReviewAnalysisRepository.Remove(salaryReviewAnalysisToDelete); Message = "Salary Review Analysis (ref #: " + referenceNumber + ") Successfully Removed"; // This will return to the main Salary Review Analysis index page displaying the default search and sort order, // meaning display the page in the "newly visited" state as if the user was visiting it for the first time. return(RedirectToAction("Index")); // This will return to the main Salary Review Analysis index page displaying the // same search and TODO: add sort order and sort property // as the user selected prior to the delete: // Note that if the user deleted the only analysis listed in the search results, that the page will now display the "No Results Found" message. //return // this.RedirectToAction<SalaryReviewAnalysisController>( // b => // b.Index(salaryReviewAnalysisSearchParamsModel.SelectedReferenceNumber, // salaryReviewAnalysisSearchParamsModel.SelectedEmployee.Id, // salaryReviewAnalysisSearchParamsModel.SelectedUser.Id, // salaryReviewAnalysisSearchParamsModel.CreationDateString)); }
/// <summary> /// Transfer editable values from source to destination /// </summary> private static void TransferValues(SalaryReviewAnalysis source, SalaryReviewAnalysis destination) { //Recommendation: Use AutoMapper //Mapper.Map(source, destination) destination.Scenarios = source.Scenarios; destination.ApprovedScenario = source.ApprovedScenario; destination.DateApproved = source.DateApproved; destination.DepartmentComments = source.DepartmentComments; destination.DeansOfficeComments = source.DeansOfficeComments; //throw new NotImplementedException(); }
public ActionResult Create(SalaryReviewAnalysis salaryReviewAnalysis) { var salaryReviewAnalysisToCreate = new SalaryReviewAnalysis(); TransferValues(salaryReviewAnalysis, salaryReviewAnalysisToCreate); if (ModelState.IsValid) { _salaryReviewAnalysisRepository.EnsurePersistent(salaryReviewAnalysisToCreate); Message = "SalaryReviewAnalysis Created Successfully"; return(RedirectToAction("Index")); } else { var viewModel = SalaryReviewAnalysisViewModel.Create(Repository); viewModel.SalaryReviewAnalysis = salaryReviewAnalysis; return(View(viewModel)); } }
/// <summary> /// Given a repository, employee ID, proposed title (optional) and user /// or repository, reference number, and user, /// Create a Salary Analysis Editor View model. /// </summary> /// <param name="repository">Database IRepository context</param> /// <param name="selectedEmployeeId">Employee ID of the employee for which to perform a new salary review analysis upon</param> /// <param name="proposedTitle">The proposed title to be used in conjunction with performing for a reclassification review; otherwise, null when performing an equity review</param> /// <param name="referenceNumber">The Salary Review Analysis reference number to be used for looking up an existing analysis</param> /// <param name="user">The logged in user either creating a new or viewing an existing analysis. Used for determining which college average(s) to display on the associated Salary Scale</param> /// <returns>A SalaryReviewAnalysisEditorViewModel populated according to the parameters provided</returns> public static SalaryReviewAnalysisEditorViewModel Create(IRepository repository, string selectedEmployeeId, string proposedTitle, string referenceNumber, User user) { Check.Require(repository != null, "Repository must be supplied"); var viewModel = new SalaryReviewAnalysisEditorViewModel { ProposedTitles = repository.OfType<Title>() .Queryable .OrderBy(t => t.AbbreviatedName) // .ThenBy(t => t.TitleCode) .ToList(), //SelectionTypes = repository.OfType<SelectionType>() //.Queryable //.Where(x => x.ShortType != "Step") //.OrderBy(s => s.SortOrder) //.ToList(), ReportDate = DateTime.Today }; var salaryScaleViewModel = new SalaryScaleViewModel(); SalaryReviewAnalysis salaryReviewAnalysis = null; SalaryScale salaryScale = null; string titleCode = null; // This title code is used in conjunction with determining colleges averages. if (!String.IsNullOrEmpty(referenceNumber) || !String.IsNullOrEmpty(selectedEmployeeId)) { // Assumes either an employee ID or reference number was provided. // We should always get here unless someone bypassed the menu page and entered a URL directly into // a web browser with some or all parameters missing. if (String.IsNullOrEmpty(referenceNumber)) { // Then an employee ID and proposed title for reclassification (optional) was provided viewModel.ReportDate = DateTime.Today; viewModel.SelectedEmployee = repository.OfType<Employee>() .Queryable .Where(e => e.id.Equals(selectedEmployeeId)) .FirstOrDefault(); salaryReviewAnalysis = new SalaryReviewAnalysis { DateInitiated = DateTime.Today }; var scenarios = new List<Scenario>(); var scenario = new Scenario { SalaryReviewAnalysis = salaryReviewAnalysis, ScenarioNumber = 1, SelectionType = "None", PercentIncrease = 0, Approved = false, SalaryAmount = viewModel.SelectedEmployee.PayRate }; scenarios.Add(scenario); salaryReviewAnalysis.Scenarios = scenarios; viewModel.SalaryReviewAnalysis = salaryReviewAnalysis; viewModel.SraEmployee = new SRAEmployee(viewModel.SelectedEmployee); salaryScale = new SalaryScale(); if (string.IsNullOrEmpty(proposedTitle) == false && !viewModel.SelectedEmployee.TitleCode.Equals(proposedTitle)) { // Then the optional proposed title was provided so this is a reclassification review. titleCode = proposedTitle; viewModel.SalaryReviewAnalysis.IsReclass = true; viewModel.ProposedTitle = repository.OfType<Title>() .Queryable .Where(p => p.TitleCode.Equals(proposedTitle)) .FirstOrDefault(); //salaryScale = repository.OfType<SalaryScale>() // .Queryable // .Where(r => r.TitleCode == proposedTitle) // .FirstOrDefault(); salaryScale = SalaryScale.GetEffectiveSalaryScale(repository, proposedTitle, DateTime.Today); viewModel.SalaryReviewAnalysis.Title = viewModel.ProposedTitle; } else { // Else this is a standard equity review. titleCode = viewModel.SelectedEmployee.TitleCode; //salaryScale = repository.OfType<SalaryScale>() // .Queryable // .Where(r => r.TitleCode == viewModel.SelectedEmployee.TitleCode) // .FirstOrDefault(); salaryScale = SalaryScale.GetEffectiveSalaryScale(repository, viewModel.SelectedEmployee.TitleCode, DateTime.Today); viewModel.SalaryReviewAnalysis.Title = viewModel.SelectedEmployee.Title; } } else if (!String.IsNullOrEmpty(referenceNumber)) { // Reference number is present so try getting existing review by reference number: viewModel.SalaryReviewAnalysis = repository.OfType<SalaryReviewAnalysis>() .Queryable .Where(x => x.ReferenceNumber.Equals(referenceNumber)) .FirstOrDefault(); if (viewModel.SalaryReviewAnalysis != null) { titleCode = viewModel.SalaryReviewAnalysis.SalaryScale.TitleCode; viewModel.SraEmployee = viewModel.SalaryReviewAnalysis.Employee; viewModel.ProposedTitle = (viewModel.SalaryReviewAnalysis.IsReclass ? viewModel.SalaryReviewAnalysis.Title : null); salaryScale = SalaryScale.GetEffectiveSalaryScale(repository, viewModel.SalaryReviewAnalysis.SalaryScale.TitleCode, viewModel.SalaryReviewAnalysis.SalaryScale.EffectiveDate); } } if (salaryScale != null) { // Determine the user's school(s) var schoolsForUser = user.Units.Select(x => x.DeansOfficeSchoolCode).Distinct().ToArray(); // and populate the corresponding college averages: salaryScaleViewModel.CollegeAverages = repository.OfType<CollegeAverage>().Queryable.Where(x => schoolsForUser.Contains(x.SchoolCode) && x.TitleCode == titleCode). ToList(); var employeesSchoolCode = viewModel.SraEmployee.HomeDepartment.SchoolCode; var collegeAverage = salaryScaleViewModel.CollegeAverages.Where(x => x.SchoolCode.Equals(employeesSchoolCode)).Select(x => x.CollegeAverageAnnual). FirstOrDefault(); viewModel.CriteriaList = SalaryReviewAnalysis.GetCriteriaList(repository, salaryScale, collegeAverage); salaryScaleViewModel.SalaryScale = salaryScale; } } viewModel.SalaryScaleViewModel = salaryScaleViewModel; return viewModel; }
public ActionResult CreateEdit(SalaryReviewAnalysis salaryReviewAnalysis, SRAEmployee sraEmployee) { const string MESSAGE_RECORD_UPDATED_SUCCESS = "Salary Review Analysis Successfully Updated "; const string MESSAGE_RECORD_SAVED_SUCCESS = "Salary Review Analysis Successfully Saved "; var message = MESSAGE_RECORD_SAVED_SUCCESS; var scenarios = salaryReviewAnalysis.Scenarios.Select(item => UpdateScenarioValues(item)).ToList(); var dateApproved = salaryReviewAnalysis.DateApproved; //if (gvSalaryReviewAnaysis.Rows.Count == 1) //{ // // Get date approved: // TextBox tbDateApproved = gvSalaryReviewAnaysis.Rows[0].FindControl("tbDateApproved") as TextBox; // if (tbDateApproved != null) // { // dateApproved = tbDateApproved.Text; // } //} //dateApproved = salaryReviewAnalysis.DateApproved; //var user = Esra.Core.Domain.User.GetByLoginId(Repository, CurrentUser.Identity.Name); var user = GetUser(); //var sra = (String.IsNullOrEmpty(ReferenceNum) == false ? SalaryReviewAnalysisBLL.GetByReferenceNumber(ReferenceNum) : null); var salaryReviewAnalysisToEdit = (String.IsNullOrEmpty(salaryReviewAnalysis.ReferenceNumber) == false ? _salaryReviewAnalysisRepository .Queryable .Where(x => x.ReferenceNumber.Equals(salaryReviewAnalysis.ReferenceNumber)) .FirstOrDefault() : null); var emp = (salaryReviewAnalysisToEdit != null ? salaryReviewAnalysisToEdit.Employee : new SRAEmployee(Repository.OfType <Employee>().Queryable.Where(x => x.Id.Equals(sraEmployee.PkEmployee)).FirstOrDefault())); //bool isReclass = (ProposedTitleCode != null && ProposedTitleCode.Equals(emp.TitleCode) == false ? true : false); var isReclass = salaryReviewAnalysis.IsReclass; //string titleCode = (isReclass ? ProposedTitleCode : emp.TitleCode); var titleCode = salaryReviewAnalysis.Title.TitleCode; if (salaryReviewAnalysisToEdit != null) { // Then this is an existing analysis: // Record exists --> Update message = MESSAGE_RECORD_UPDATED_SUCCESS; } else { // Else this is a new analysis: salaryReviewAnalysisToEdit = new SalaryReviewAnalysis() { DateInitiated = DateTime.Today, //InitiatedByReviewerName = user.FullName, //OriginatingDepartment = Department.GetOriginatingDepartmentForUser(Repository, user.EmployeeID), Title = Repository.OfType <Title>() .Queryable .Where(t => t.TitleCode.Equals(titleCode)) .FirstOrDefault(), Employee = emp, SalaryScale = SalaryScale.GetEffectiveSalaryScale(Repository, titleCode, DateTime.Today), CurrentTitleCode = emp.TitleCode, IsReclass = isReclass }; } salaryReviewAnalysisToEdit.InitiatedByReviewerName = salaryReviewAnalysis.InitiatedByReviewerName; salaryReviewAnalysisToEdit.OriginatingDepartment = salaryReviewAnalysis.OriginatingDepartment; //if (String.IsNullOrEmpty(dateApproved) == false) salaryReviewAnalysisToEdit.DateApproved = dateApproved ?? null; salaryReviewAnalysisToEdit.DeansOfficeComments = salaryReviewAnalysis.DeansOfficeComments; salaryReviewAnalysisToEdit.DepartmentComments = salaryReviewAnalysis.DepartmentComments; salaryReviewAnalysisToEdit.Scenarios = scenarios; //TransferValues(salaryReviewAnalysis, salaryReviewAnalysisToEdit); if (ModelState.IsValid) { //_salaryReviewAnalysisRepository.EnsurePersistent(salaryReviewAnalysisToEdit); SalaryReviewAnalysis.UpdateRecord(Repository, salaryReviewAnalysisToEdit); // At this point the reference number has been if a newly created analysis! //Session["Message"] = message; var referenceNumber = salaryReviewAnalysisToEdit.ReferenceNumber; Message = Message = "Salary Review Analysis (ref #: " + referenceNumber + ") Successfully Saved";; //var values = new System.Web.Routing.RouteValueDictionary { { "referenceNumber", referenceNumber } }; //return RedirectToAction("Details", values); // -- or -- //return RedirectToAction("Details", new { referenceNumber }); // -- or -- return(this.RedirectToAction <SalaryReviewAnalysisController>(a => a.Details(referenceNumber))); } else { var viewModel = SalaryReviewAnalysisViewModel.Create(Repository); viewModel.SalaryReviewAnalysis = salaryReviewAnalysis; return(View(viewModel)); } }
/// <summary> /// Given a repository, employee ID, proposed title (optional) and user /// or repository, reference number, and user, /// Create a Salary Analysis Editor View model. /// </summary> /// <param name="repository">Database IRepository context</param> /// <param name="selectedEmployeeId">Employee ID of the employee for which to perform a new salary review analysis upon</param> /// <param name="proposedTitle">The proposed title to be used in conjunction with performing for a reclassification review; otherwise, null when performing an equity review</param> /// <param name="referenceNumber">The Salary Review Analysis reference number to be used for looking up an existing analysis</param> /// <param name="user">The logged in user either creating a new or viewing an existing analysis. Used for determining which college average(s) to display on the associated Salary Scale</param> /// <returns>A SalaryReviewAnalysisEditorViewModel populated according to the parameters provided</returns> public static SalaryReviewAnalysisEditorViewModel Create(IRepository repository, string selectedEmployeeId, string proposedTitle, string referenceNumber, User user) { Check.Require(repository != null, "Repository must be supplied"); var viewModel = new SalaryReviewAnalysisEditorViewModel { ProposedTitles = repository.OfType <Title>() .Queryable .OrderBy(t => t.AbbreviatedName) // .ThenBy(t => t.TitleCode) .ToList(), //SelectionTypes = repository.OfType<SelectionType>() //.Queryable //.Where(x => x.ShortType != "Step") //.OrderBy(s => s.SortOrder) //.ToList(), ReportDate = DateTime.Today }; var salaryScaleViewModel = new SalaryScaleViewModel(); SalaryReviewAnalysis salaryReviewAnalysis = null; SalaryScale salaryScale = null; string titleCode = null; // This title code is used in conjunction with determining colleges averages. if (!String.IsNullOrEmpty(referenceNumber) || !String.IsNullOrEmpty(selectedEmployeeId)) { // Assumes either an employee ID or reference number was provided. // We should always get here unless someone bypassed the menu page and entered a URL directly into // a web browser with some or all parameters missing. if (String.IsNullOrEmpty(referenceNumber)) { // Then an employee ID and proposed title for reclassification (optional) was provided viewModel.ReportDate = DateTime.Today; viewModel.SelectedEmployee = repository.OfType <Employee>() .Queryable .Where(e => e.id.Equals(selectedEmployeeId)) .FirstOrDefault(); salaryReviewAnalysis = new SalaryReviewAnalysis { DateInitiated = DateTime.Today }; var scenarios = new List <Scenario>(); var scenario = new Scenario { SalaryReviewAnalysis = salaryReviewAnalysis, ScenarioNumber = 1, SelectionType = "None", PercentIncrease = 0, Approved = false, SalaryAmount = viewModel.SelectedEmployee.PayRate }; scenarios.Add(scenario); salaryReviewAnalysis.Scenarios = scenarios; viewModel.SalaryReviewAnalysis = salaryReviewAnalysis; viewModel.SraEmployee = new SRAEmployee(viewModel.SelectedEmployee); salaryScale = new SalaryScale(); if (string.IsNullOrEmpty(proposedTitle) == false && !viewModel.SelectedEmployee.TitleCode.Equals(proposedTitle)) { // Then the optional proposed title was provided so this is a reclassification review. titleCode = proposedTitle; viewModel.SalaryReviewAnalysis.IsReclass = true; viewModel.ProposedTitle = repository.OfType <Title>() .Queryable .Where(p => p.TitleCode.Equals(proposedTitle)) .FirstOrDefault(); //salaryScale = repository.OfType<SalaryScale>() // .Queryable // .Where(r => r.TitleCode == proposedTitle) // .FirstOrDefault(); salaryScale = SalaryScale.GetEffectiveSalaryScale(repository, proposedTitle, DateTime.Today); viewModel.SalaryReviewAnalysis.Title = viewModel.ProposedTitle; } else { // Else this is a standard equity review. titleCode = viewModel.SelectedEmployee.TitleCode; //salaryScale = repository.OfType<SalaryScale>() // .Queryable // .Where(r => r.TitleCode == viewModel.SelectedEmployee.TitleCode) // .FirstOrDefault(); salaryScale = SalaryScale.GetEffectiveSalaryScale(repository, viewModel.SelectedEmployee.TitleCode, DateTime.Today); viewModel.SalaryReviewAnalysis.Title = viewModel.SelectedEmployee.Title; } } else if (!String.IsNullOrEmpty(referenceNumber)) { // Reference number is present so try getting existing review by reference number: viewModel.SalaryReviewAnalysis = repository.OfType <SalaryReviewAnalysis>() .Queryable .Where(x => x.ReferenceNumber.Equals(referenceNumber)) .FirstOrDefault(); if (viewModel.SalaryReviewAnalysis != null) { titleCode = viewModel.SalaryReviewAnalysis.SalaryScale.TitleCode; viewModel.SraEmployee = viewModel.SalaryReviewAnalysis.Employee; viewModel.ProposedTitle = (viewModel.SalaryReviewAnalysis.IsReclass ? viewModel.SalaryReviewAnalysis.Title : null); salaryScale = SalaryScale.GetEffectiveSalaryScale(repository, viewModel.SalaryReviewAnalysis.SalaryScale.TitleCode, viewModel.SalaryReviewAnalysis.SalaryScale.EffectiveDate); } } if (salaryScale != null) { // Determine the user's school(s) var schoolsForUser = user.Units.Select(x => x.DeansOfficeSchoolCode).Distinct().ToArray(); // and populate the corresponding college averages: salaryScaleViewModel.CollegeAverages = repository.OfType <CollegeAverage>().Queryable.Where(x => schoolsForUser.Contains(x.SchoolCode) && x.TitleCode == titleCode). ToList(); var employeesSchoolCode = viewModel.SraEmployee.HomeDepartment.SchoolCode; var collegeAverage = salaryScaleViewModel.CollegeAverages.Where(x => x.SchoolCode.Equals(employeesSchoolCode)).Select(x => x.CollegeAverageAnnual). FirstOrDefault(); viewModel.CriteriaList = SalaryReviewAnalysis.GetCriteriaList(repository, salaryScale, collegeAverage); salaryScaleViewModel.SalaryScale = salaryScale; } } viewModel.SalaryScaleViewModel = salaryScaleViewModel; return(viewModel); }