/// <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> /// Determines whether [is valid rating post] [the specified pf number]. /// </summary> /// <param name="pfNumber">The pf number.</param> /// <param name="cycle">The cycle.</param> /// <param name="kpiRate">The kpi rate.</param> /// <returns></returns> public bool IsValidRatingPost(int pfNumber, int? cycle, SelfAssessmentRating kpiRate) { try { var check = (from k in this.db.Kpis join eo in this.db.EmployeeObjectives on k.EmployeeObjectiveId equals eo.Id join o in this.db.Objectives on eo.ObjectiveId equals o.Id join e in this.db.employees on eo.EmployeeId equals e.ID where k.Id == kpiRate.KpiId && o.CycleId == cycle && e.Code == pfNumber.ToString() select new{k.Id, k.Weight}) .FirstOrDefault(); if (check != null) { if (check.Weight != null && kpiRate.EmployeeRating >= 0 && kpiRate.EmployeeRating <= check.Weight) { return true; } else { return false; } } else { return false; } } catch (DataException) { // // Handle exception. return false; } catch (Exception) { // // Handle exception. return false; } }