using Ease.Core.Model; using System; using System.Collections.Generic; using System.Data; using System.Linq; namespace HRM.BO { public class DataUploadException { //List oadparamemployees; List oempAppraisalRatings = null; private List _errorOrSuccessList; public DataUploadException() { _errorOrSuccessList = new List(); } public List ErrorOrSuccessList { get { return _errorOrSuccessList; } } public void UploadException(int uploadId, DataTable _uploadData, DataUploadColumnDefinition oColumnDefinition) { switch (uploadId) { case (int)42: { this.UploadAppraisalPoint(_uploadData, oColumnDefinition); break; } default: break; } } public void SaveException(int uploadId) { switch (uploadId) { case (int)42: { this.SaveAppraisalPoint(); break; } default: break; } } private void SaveAppraisalPoint() { try { if (oempAppraisalRatings != null && oempAppraisalRatings.Count >= 1) { EmpAppraisalRating.Save(oempAppraisalRatings); } } catch (Exception ex) { throw new ServiceException(ex.Message); } } private void UploadAppraisalPoint(DataTable _uploadData, DataUploadColumnDefinition oColumnDefinition) { List oemployees = new List(); //Employee.Get(); Employee oemployee = null; int nRow = 0; oempAppraisalRatings = new List(); List allpoints = AppraisalPoint.Get(EnumStatus.Active); try { foreach (DataRow dr in _uploadData.Rows) { nRow = nRow + 1; oemployee = oemployees.Find(delegate (Employee emp) { return emp.EmployeeNo == dr["Employee No"].ToString().Trim(); }); if (oemployee != null) { EmpAppraisalRating obEmpAppRating = new EmpAppraisalRating(); string ratingName = dr["Rating"].ToString().Trim(); var findRatingName = allpoints.Where(ob => ob.Name.ToLower() == ratingName.ToLower()); if (findRatingName.Count() > 0) { obEmpAppRating.AppraisalPointRatingID = findRatingName.First().ID; obEmpAppRating.EmployeeID = oemployee.ID; //obEmpAppRating.AppraisalYear = Ease.CoreV35.Utility.Global.DateFunctions.LastDateOfYear(oColumnDefinition.ItemThreeSelectedDate.Value); oempAppraisalRatings.Add(obEmpAppRating); } else { _errorOrSuccessList.Add(UploadErrorOrSuccess.Create("Employee No.", nRow, "(" + dr["Employee No"].ToString() + ")" + "Rating not found in the existing data")); } } else { _errorOrSuccessList.Add(UploadErrorOrSuccess.Create("Employee No.", nRow, "(" + dr["Employee No"].ToString() + ")" + "Employee not found for in the existing data")); } } } catch (Exception ex) { throw new ServiceException("Error occurred on row:" + nRow + " Reason:" + ex.Message); } } } }