/// <summary> /// Capture the employee ratings. /// </summary> /// <param name="pfNumber">The pf number.</param> /// <param name="cycle">The cycle.</param> /// <param name="rating">The rating.</param> /// <returns> /// Flag indicating whether the operation was a success. /// </returns> public bool EmployeeRating(int pfNumber, int? cycle, SelfAssessmentRating rating) { if (this.rules.IsPfNumberValid(pfNumber)) { if (this.rules.IsValidRatingPost(pfNumber, cycle, rating)) { Kpi kpiEdit = new Kpi { Id = Int32.Parse(rating.KpiId.ToString()), EmployeeObjectiveId = Int32.Parse(rating.EmployeeObjectiveId.ToString()), Title = rating.KpiTitle, Weight = rating.Weight, Measure = rating.Measure, EmployeeRating = rating.EmployeeRating, FinalRating = rating.FinalRating }; this.db.Entry(kpiEdit).State = System.Data.Entity.EntityState.Modified; this.db.SaveChanges(); return true; } else { // // Handle invalid rating post. return false; } } else { // // Handle invalid pf number. return false; } }
/// <summary> /// Adds the kpi. /// </summary> /// <param name="newKpi">The new kpi.</param> /// <param name="pfNumber">The pf number.</param> /// <returns>Flag indicating whether the operation was successful.</returns> public bool AddKpi(AddKpi newKpi, int pfNumber, int? cycle) { try { if (this.kpiRule.IsPfNumberValid(pfNumber)) { if (this.kpiRule.IsKpiAddPostValid(pfNumber, cycle, newKpi.Weight, newKpi.EmployeeObjectiveId)) { // Add new KPI. Kpi kpiCreation = new Kpi { EmployeeObjectiveId = newKpi.EmployeeObjectiveId, Title = newKpi.KpiTitle, Weight = newKpi.Weight, Measure = newKpi.Measure, EmployeeRating = 0, FinalRating = 0 }; this.db.Kpis.Add(kpiCreation); this.db.SaveChanges(); return true; } else { // // Handle invalid post. return false; } } else { // // Handle invalid pf number return false; } } catch (DataException) { // // Handle the exception. return false; } catch (Exception) { // // Handle the exception. return false; } }
/// <summary> /// Edits the kpi. /// </summary> /// <param name="kpiUpdate">The kpi update.</param> /// <param name="pfNumber">The pf number.</param> /// <param name="cycle">The cycle.</param> /// <returns>Flag indicating whether the operation was successful.</returns> public bool EditKpi(EditKpi kpiUpdate, int pfNumber, int? cycle) { try { if (this.kpiRule.IsPfNumberValid(pfNumber)) { if (this.kpiRule.IsKpiEditPostValid(pfNumber, kpiUpdate, cycle)) { Kpi kpiEdit = new Kpi { Id = kpiUpdate.KpiId, EmployeeObjectiveId = kpiUpdate.EmployeeObjectiveId, Title = kpiUpdate.KpiTitle, Weight = kpiUpdate.Weight, Measure = kpiUpdate.Measure, EmployeeRating = kpiUpdate.EmployeeRating, FinalRating = kpiUpdate.FinalRating }; this.db.Entry(kpiEdit).State = System.Data.Entity.EntityState.Modified; this.db.SaveChanges(); return true; } else { // // Handle invalid edit post. return false; } } else { return false; } } catch (DataException) { // // Handle exception. return false; } catch (Exception) { // // Handle Exception. return false; } }