public static PMS.Model.DTO.Cycle.Cycle MapCycleEntityToDTO(PMS.Model.Context.PMS_CYCLE entity, bool mapChildEntities) { PMS.Model.DTO.Cycle.Cycle obj_dto = new PMS.Model.DTO.Cycle.Cycle() { Id = entity.ID, Name = entity.NAME, Status = entity.PMS_MST_STATUS == null ? null : MapStatusEntityToDTO(entity.PMS_MST_STATUS), Stage = entity.PMS_MST_STAGE == null ? null : MapStageEntityToDTO(entity.PMS_MST_STAGE), StartedTimestamp = entity.STARTED_TIMESTAMP }; if (mapChildEntities) { obj_dto.CycleStages = Lib.Utility.Common.IsNullOrEmptyList(entity.PMS_CYCLE_STAGE) == true ? null : MapCycleStageEntitiesToDTOs(entity.PMS_CYCLE_STAGE.ToList()); obj_dto.Appriasals = Lib.Utility.Common.IsNullOrEmptyList(entity.PMS_APPRAISAL) == true ? null : MapAppraisalEntitiesToDTOs(entity.PMS_APPRAISAL.ToList(), true); } return obj_dto; }
public ActionResult NewCycle(FormCollection form) { string message = string.Empty; Dictionary<string, string> dict = FormCollectionToDict(form); bool boo_start_cycle = Convert.ToInt32(dict["startcycle"]) == 1 ? true : false; Models.DTO.NewCycleManagementPage obj_cycle_management_page = new Models.DTO.NewCycleManagementPage(); if (!boo_start_cycle) { if (form["Stage1EndDate"] != null && form["Stage3EndDate"] != null) { if (string.IsNullOrEmpty(dict["Stage1EndDate"]) || string.IsNullOrEmpty(dict["Stage1EndDate"])) { ViewData.Model = obj_cycle_management_page; TempData["ErrorMessage"] = "Please enter all the dates for the appraisal cycle before retrieving the participants."; return View(); } DateTime eligibilityRangeStart = DateTime.ParseExact(form["Stage1EndDate"].ToString(), "d/M/yyyy", null); DateTime eligibilityRangeEnd = DateTime.ParseExact(form["Stage3EndDate"].ToString(), "d/M/yyyy", null); List<Model.DTO.Core.Employee> lst_selected_employees = Business.AppraisalManager.GetEligibleEmployeesForCycle(eligibilityRangeStart, eligibilityRangeEnd); if (!Lib.Utility.Common.IsNullOrEmptyList(lst_selected_employees)) { System.Web.HttpContext.Current.Session.Add("CycleParticipantsList", lst_selected_employees); obj_cycle_management_page.Participants = lst_selected_employees.OrderBy(rec => rec.Department.Name).ThenBy(rec => rec.PreferredName).ToList(); } else { obj_cycle_management_page.Participants = new List<Model.DTO.Core.Employee>(); } System.Web.HttpContext.Current.Session.Add("CycleName", dict["cyclename"].ToString()); System.Web.HttpContext.Current.Session.Add("Stage1StartDate", dict["Stage1StartDate"].ToString()); System.Web.HttpContext.Current.Session.Add("Stage1EndDate", dict["Stage1EndDate"].ToString()); System.Web.HttpContext.Current.Session.Add("Stage2StartDate", dict["Stage2StartDate"].ToString()); System.Web.HttpContext.Current.Session.Add("Stage2EndDate", dict["Stage2EndDate"].ToString()); System.Web.HttpContext.Current.Session.Add("Stage3StartDate", dict["Stage3StartDate"].ToString()); System.Web.HttpContext.Current.Session.Add("Stage3EndDate", dict["Stage3EndDate"].ToString()); System.Web.HttpContext.Current.Session.Add("Stage1SubmissionDeadline", dict["Stage1SubmissionDeadline"].ToString()); System.Web.HttpContext.Current.Session.Add("Stage1Level1ApprovalDeadline", dict["Stage1Level1ApprovalDeadline"].ToString()); System.Web.HttpContext.Current.Session.Add("Stage1Level2ApprovalDeadline", dict["Stage1Level2ApprovalDeadline"].ToString()); System.Web.HttpContext.Current.Session.Add("Stage2SubmissionDeadline", dict["Stage1SubmissionDeadline"].ToString()); System.Web.HttpContext.Current.Session.Add("Stage2Level1ApprovalDeadline", dict["Stage1Level1ApprovalDeadline"].ToString()); System.Web.HttpContext.Current.Session.Add("Stage2Level2ApprovalDeadline", dict["Stage1Level2ApprovalDeadline"].ToString()); } ViewData.Model = obj_cycle_management_page; dict.Add("strStage1EndDate", Lib.Utility.Common.ChangeDateFormatVS(dict["Stage1EndDate"].ToString())); dict.Add("strStage3EndDate", Lib.Utility.Common.ChangeDateFormatVS(dict["Stage3EndDate"].ToString())); TempData["QueryData"] = dict; return View(); } else { if (System.Web.HttpContext.Current.Session["CycleParticipantsList"] != null) { PMS.Model.DTO.Cycle.Cycle obj_cycle = new PMS.Model.DTO.Cycle.Cycle() { Name = form["cyclename"].Trim(), Stage = new Model.DTO.Master.Stage() { Id = Model.PMSConstants.STAGE_ID_PRE_CYCLE }, Status = new Model.DTO.Master.Status() { Id = Model.PMSConstants.STATUS_ID_OPEN }, Starter = new Model.DTO.Core.Employee() { Id = CurrentUser.Id }, StartedTimestamp = DateTime.Now }; Dictionary<string, DateTime> dict_cycle_stage_dates = new Dictionary<string, DateTime>(); dict_cycle_stage_dates.Add("PreCStart", DateTime.Now.Date); dict_cycle_stage_dates.Add("PreCEnd", DateTime.ParseExact(dict["Stage1StartDate"], "dd/MM/yyyy", null).AddDays(-1)); dict_cycle_stage_dates.Add("Stage1StartDate", DateTime.ParseExact(dict["Stage1StartDate"], "dd/MM/yyyy", null)); dict_cycle_stage_dates.Add("Stage1EndDate", DateTime.ParseExact(dict["Stage1EndDate"], "dd/MM/yyyy", null)); dict_cycle_stage_dates.Add("Stage2StartDate", DateTime.ParseExact(dict["Stage2StartDate"], "dd/MM/yyyy", null)); dict_cycle_stage_dates.Add("Stage2EndDate", DateTime.ParseExact(dict["Stage2EndDate"], "dd/MM/yyyy", null)); dict_cycle_stage_dates.Add("Stage3StartDate", DateTime.ParseExact(dict["Stage3StartDate"], "dd/MM/yyyy", null)); dict_cycle_stage_dates.Add("Stage3EndDate", DateTime.ParseExact(dict["Stage3EndDate"], "dd/MM/yyyy", null)); dict_cycle_stage_dates.Add("Stage1SubmissionDeadline", DateTime.ParseExact(dict["Stage1SubmissionDeadline"], "dd/MM/yyyy", null)); dict_cycle_stage_dates.Add("Stage1Level1ApprovalDeadline", DateTime.ParseExact(dict["Stage1Level1ApprovalDeadline"], "dd/MM/yyyy", null)); dict_cycle_stage_dates.Add("Stage1Level2ApprovalDeadline", DateTime.ParseExact(dict["Stage1Level2ApprovalDeadline"], "dd/MM/yyyy", null)); dict_cycle_stage_dates.Add("Stage2SubmissionDeadline", DateTime.ParseExact(dict["Stage2SubmissionDeadline"], "dd/MM/yyyy", null)); dict_cycle_stage_dates.Add("Stage2Level1ApprovalDeadline", DateTime.ParseExact(dict["Stage2Level1ApprovalDeadline"], "dd/MM/yyyy", null)); dict_cycle_stage_dates.Add("Stage2Level2ApprovalDeadline", DateTime.ParseExact(dict["Stage2Level2ApprovalDeadline"], "dd/MM/yyyy", null)); obj_cycle.CycleStages = CreateDefaultStagesForNewCycle(dict_cycle_stage_dates); obj_cycle.Appriasals = Business.AppraisalManager.CreateAppraisalsForNewCycle((List<Model.DTO.Core.Employee>)System.Web.HttpContext.Current.Session["CycleParticipantsList"], obj_cycle.CycleStages, CurrentUser); if (Business.AppraisalManager.CreateNewCycle(obj_cycle, Model.Mappers.CoreMapper.MapUserDTOToEmployeeDTO(CurrentUser), out message)) { ClearAllCreatedSessionObjects(); return Redirect(Url.Content("~/")); } else { TempData["ErrorMessage"] = "Unable to save cycle information. Please try again or contact IT Department."; return View(); } } else { TempData["ErrorMessage"] = "Cycle information is not found. Please try again or contact IT Department."; return View(); } } }