/// <summary> /// To Save KPI for the Client /// </summary> /// <param name="clientKPI"></param> /// <returns></returns> public bool SaveKPIForClient(ClientKPISetupViewModel clientKPI) { try { if (clientKPI?.KpiQuestions?.Count > 0) { ClientKPISetup clientKPISetup = new ClientKPISetup(); clientKPISetup.ClientCode = clientKPI.ClientCode; foreach (KPISetupViewModel KPIViewModel in clientKPI.KpiQuestions) { KPISetup kPISetup = new KPISetup(); kPISetup.ClientStandard = KPIViewModel.ClientStandard; kPISetup.Sla = KPIViewModel.Sla; kPISetup.Kpi.KPIID = KPIViewModel.Kpi.KpiId; kPISetup.ClientKPIMapId = KPIViewModel.clientKPIMapId; foreach (AllUsersViewModel user in KPIViewModel.SendTo) { kPISetup.SendTo.Add(new AllUsers() { ID = user.ID, Email = user.Email }); } clientKPISetup.KPIQuestions.Add(kPISetup); } return(_kpiRepository.SaveKPIForClient(clientKPISetup)); } else { return(false); } } catch (Exception ex) { _logger.Log(ex, LogLevel.Error, ex.Message); return(false); } }
/// <summary> /// /// </summary> /// <param name="clientCode"></param> /// <returns></returns> public ClientKPISetupViewModel GetClientAssignedKPIs(string clientCode) { try { ClientKPISetupViewModel clientKPISetupViewModel = new ClientKPISetupViewModel(); ClientKPISetup clientAssignedM3KPIs = _kpiRepository.GetClientAssignedM3KPIs(clientCode); if (clientAssignedM3KPIs.KPIQuestions?.Count > 0) { foreach (KPISetup clientKPIDto in clientAssignedM3KPIs.KPIQuestions) { KPISetupViewModel clientKPI = new KPISetupViewModel(); clientKPI.ClientStandard = clientKPIDto.ClientStandard; if (!string.IsNullOrEmpty(clientKPI.ClientStandard)) { string[] words = clientKPI.ClientStandard.Split(','); clientKPI.AlertLevel = words[0]; clientKPI.AlertValue = words[1]; clientKPI.ClientStandard = clientKPI.ClientStandard.Replace(",", " "); } clientKPI.Sla = clientKPIDto.Sla; clientKPI.clientKPIMapId = clientKPIDto.ClientKPIMapId; clientKPI.Kpi.ChecklistTypeViewModel.CheckListTypeCode = clientKPIDto.Kpi.Source.CheckListTypeCode; clientKPI.Kpi.CompanyStandard = clientKPIDto.Kpi.AlertLevel.Replace(",", " "); clientKPI.Kpi.IsUniversal = clientKPIDto.Kpi.IsUniversal; clientKPI.Kpi.KpiDescription = clientKPIDto.Kpi.KPIDescription; clientKPI.Kpi.KpiId = clientKPIDto.Kpi.KPIID; if (clientKPIDto.Kpi.Measure != null && clientKPIDto.Kpi.Source.CheckListTypeCode == DomainConstants.M3) { clientKPI.Kpi.M3MeasureViewModel.MeasureCode = clientKPIDto.Kpi.Measure.MeasureCode; clientKPI.Kpi.M3MeasureViewModel.MeasureUnit = clientKPIDto.Kpi.Measure.MeasureUnit; } else { clientKPI.Kpi.M3MeasureViewModel = null; } if (clientKPIDto.SendTo?.Count > 0) { foreach (AllUsers user in clientKPIDto.SendTo) { clientKPI.SendTo.Add(BusinessMapper.AllUsersBusinessToAllUsesrViewModel(user)); } } clientKPISetupViewModel.KpiQuestions.Add(clientKPI); } } ClientKPIDetails clientAssignedWeeklyMonthlyKPIs = _kpiRepository.GetClientAssignedWeeklyMonthlyKPIs(clientCode); List <int> kpiIds = clientAssignedWeeklyMonthlyKPIs.clientKPIAssignedDetails.Select(c => c.KPIID)?.Distinct()?.ToList(); foreach (int kpiId in kpiIds) { List <ClientKPIAssignedDetails> kpiDetailsForKPIId = clientAssignedWeeklyMonthlyKPIs.clientKPIAssignedDetails.Where(k => k.KPIID == kpiId)?.OrderBy(k => k.ClientKPIMapID).ToList(); KPISetupViewModel clientKPI = new KPISetupViewModel(); if (kpiDetailsForKPIId.Count >= 2) { if (kpiDetailsForKPIId.Count > 2) { kpiDetailsForKPIId = kpiDetailsForKPIId.Where(k => k.KPIID == kpiId && k.ChecklistEndDate != DateTime.MaxValue.Date).ToList(); } if (kpiDetailsForKPIId.Count == 2) { ClientKPIAssignedDetails previousClientKPI = kpiDetailsForKPIId[0]; ClientKPIAssignedDetails newClientKPI = kpiDetailsForKPIId[1]; if (previousClientKPI.IsKPI) { ClientKPIAssignedDetailsToKPISetupViewModel(clientAssignedWeeklyMonthlyKPIs, clientKPI, previousClientKPI); if (!newClientKPI.IsKPI)//From KPI to made NonKPI //4th,5th scenario { clientKPI.Info = InfoMessages.ItemWillRemoveFrom + previousClientKPI.QuestionEndDate.Date.ToString("MM/dd/yyyy"); clientKPI.FutureRemoverOrUniversal = true; } else if (previousClientKPI.IsUnivarsal && !newClientKPI.IsUnivarsal) //From Universal to made non Universal 3rd scenario { clientKPI.Info = InfoMessages.ItemNonUniversalFrom + previousClientKPI.QuestionEndDate.Date.ToString("MM/dd/yyyy"); } else if (!previousClientKPI.IsUnivarsal && newClientKPI.IsUnivarsal) //Ftom nonUniversal to made universal 2nd Scenario { clientKPI.Info = InfoMessages.ItemUniversalFrom + newClientKPI.QuestionEffectiveDate.Date.ToString("MM/dd/yyyy"); clientKPI.FutureRemoverOrUniversal = true; } else if (previousClientKPI.ChecklistQuestionEffectiveDate > DateTime.Now.Date && newClientKPI.ChecklistQuestionEffectiveDate > DateTime.Now.Date) //No changes on KPI and Universal { clientKPI.Info = InfoMessages.ItemEffectiveFrom + previousClientKPI.ChecklistQuestionEffectiveDate.ToString("MM/dd/yyyy"); } else if (previousClientKPI.ChecklistEffectiveDate > DateTime.Now.Date && newClientKPI.ChecklistEffectiveDate > DateTime.Now.Date) //No changes on KPI and Universal { clientKPI.Info = InfoMessages.ItemEffectiveFrom + previousClientKPI.ChecklistEffectiveDate.ToString("MM/dd/yyyy"); } clientKPISetupViewModel.KpiQuestions.Add(clientKPI); } else if (!previousClientKPI.IsKPI && newClientKPI.IsKPI) //If previously non KPI and now made KPI { ClientKPIAssignedDetailsToKPISetupViewModel(clientAssignedWeeklyMonthlyKPIs, clientKPI, newClientKPI); if (newClientKPI.ChecklistEffectiveDate > DateTime.Now.Date)// To check if checklist is starting from future { clientKPI.Info = InfoMessages.ItemEffectiveFrom + newClientKPI.ChecklistEffectiveDate.ToString("MM/dd/yyyy"); } else if (newClientKPI.ChecklistQuestionEffectiveDate > DateTime.Now.Date) //If assigned Quedtion is starting from future { clientKPI.Info = InfoMessages.ItemEffectiveFrom + newClientKPI.ChecklistQuestionEffectiveDate.ToString("MM/dd/yyyy"); } if (newClientKPI.IsUnivarsal) { clientKPI.FutureRemoverOrUniversal = true; } clientKPISetupViewModel.KpiQuestions.Add(clientKPI); } } } else { //1st scenario ClientKPIAssignedDetails currentAssignedKPI = kpiDetailsForKPIId.FirstOrDefault(); ClientKPIAssignedDetailsToKPISetupViewModel(clientAssignedWeeklyMonthlyKPIs, clientKPI, currentAssignedKPI); if (currentAssignedKPI.KPIAssignedEndDate != DateTime.MaxValue.Date) //To check if the KPI is ending in future and only one record is assigned { clientKPI.Info = InfoMessages.ItemWillRemoveFrom + currentAssignedKPI.KPIAssignedEndDate.Date.ToString("MM/dd/yyyy"); clientKPI.FutureRemoverOrUniversal = true; } else if (currentAssignedKPI.ChecklistEndDate != DateTime.MaxValue.Date) //If assigned Question is starting from future { clientKPI.Info = InfoMessages.ItemWillRemoveFrom + currentAssignedKPI.ChecklistEndDate.Date.ToString("MM/dd/yyyy"); clientKPI.FutureRemoverOrUniversal = true; } else if (currentAssignedKPI.ChecklistEffectiveDate > DateTime.Now.Date)// To check if checklist is starting from future { clientKPI.Info = InfoMessages.ItemEffectiveFrom + currentAssignedKPI.ChecklistEffectiveDate.ToString("MM/dd/yyyy"); } else if (currentAssignedKPI.ChecklistQuestionEffectiveDate > DateTime.Now.Date) //If assigned Question to checklist is starting from future { clientKPI.Info = InfoMessages.ItemEffectiveFrom + currentAssignedKPI.ChecklistQuestionEffectiveDate.ToString("MM/dd/yyyy"); } else if (currentAssignedKPI.QuestionEffectiveDate > DateTime.Now.Date) //If assigned Question is starting from future { clientKPI.Info = InfoMessages.ItemEffectiveFrom + currentAssignedKPI.QuestionEffectiveDate.ToString("MM/dd/yyyy"); } clientKPISetupViewModel.KpiQuestions.Add(clientKPI); } } return(clientKPISetupViewModel); } catch (Exception ex) { _logger.Log(ex, LogLevel.Error, ex.Message); return(null); } }
public bool SaveKPIForClient([FromBody] ClientKPISetupViewModel clientKPI) { return(_kpiBusiness.SaveKPIForClient(clientKPI)); }