public AbsencePlanningResponse SaveAbsencePlanning(AbsencePlanningResponse response) { return RemoteService.SaveAbsencePlanning(response); }
public AbsencePlanningResponse SaveAbsencePlanning(AbsencePlanningResponse response) { // diction id of empluyees which absences or holidays number changed Dictionary<long, object> d_ids = new Dictionary<long, object>(); if (response.DeletedIds != null) { List<long> ids = new List<long>(response.DeletedIds); List<AbsenceTimePlanning> listAbsences = AbsenceTimePlanningService.FindByIDList(ids); if (listAbsences != null) { foreach (AbsenceTimePlanning a in listAbsences) d_ids[a.EmployeeID] = a; } AbsenceTimePlanningService.DeleteList(listAbsences);// DeleteListByID(ids); } if (response.ModifiedEntity != null) { List<EmployeeHolidaysInfo> lst = new List<EmployeeHolidaysInfo>(response.ModifiedEntity); EmployeeHolidaysInfoService.SaveOrUpdateList(lst); foreach (EmployeeHolidaysInfo o in lst) d_ids[o.EmployeeID] = o; } if (response.NewAbsences != null) { foreach (AbsenceTimeRange a in response.NewAbsences) { Debug.Assert(a.EmployeeID > 0); Debug.Assert(a.AbsenceID > 0); Debug.Assert(a.ID <= 0); d_ids[a.EmployeeID] = a; ClearEmployeePlanningTime(a.EmployeeID, a.Date, a.Date); AbsenceTimePlanning entity = new AbsenceTimePlanning(a.Begin, a.End, a.Time, a.AbsenceID, a.EmployeeID); entity.ID = 0; entity.Date = a.Date; AbsenceTimePlanningService.SaveOrUpdate(entity); a.ID = entity.ID; } } if (d_ids.Count > 0) { long[] ids = new long[d_ids.Count]; d_ids.Keys.CopyTo(ids, 0); ExEmployeeHolidays.CalculateAndUpdate(ids, response.Year); } return response; }
private void SyncResponses(AbsencePlanningResponse new_response) { if (new_response.DeletedIds != null && _ids_absences_from_server != null && _ids_absences_from_server.Length > 0) { foreach (long id in new_response.DeletedIds) { int i = Array.BinarySearch<long>(_ids_absences_from_server, id); if (i >= 0) { _ids_absences_from_server[i] = 0; } } } if (new_response.ModifiedEntity != null && _response.ModifiedEntity != null) { foreach (EmployeeHolidaysInfo info in new_response.ModifiedEntity) { foreach (EmployeeHolidaysInfo info1 in _response.ModifiedEntity) { if (info.EmployeeID == info1.EmployeeID) { info1.ID = info.ID; break; } } } } List<long> ids = new List<long>(); if (_ids_absences_from_server != null) { for (int i = 0; i < _ids_absences_from_server.Length; i++) { if (_ids_absences_from_server[i] != 0) ids.Add(_ids_absences_from_server[i]); } } if (new_response.NewAbsences != null && _response.NewAbsences != null) { for (int i = 0; i < new_response.NewAbsences.Length; i++) { _response.NewAbsences[i].ID = new_response.NewAbsences[i].ID; ids.Add(new_response.NewAbsences[i].ID); } } _ids_absences_from_server = ids.ToArray(); }
private void BuildResponse() { if (!Modified) return; _response = new AbsencePlanningResponse(); _response.Year = Year; _response.StoreID = this.CurrentStore.ID; BuildDeltaForAbsences(); _response.DeletedIds = _ids_removed_absences; _response.NewAbsences = _list_New_Abences.ToArray (); if (_EmployeesList != null) { List<EmployeeHolidaysInfo> lst = new List<EmployeeHolidaysInfo>(); foreach (BzEmployeeHoliday entity in _EmployeesList) { if (entity.IsModified()) { lst.Add(entity.UpdateEntity()); } } _response.ModifiedEntity = lst.ToArray(); } }
public void SaveData(bool bAsk) { if (Modified) { if (!bAsk || XtraMessageBox.Show(GetLocalized("QuestionSavePlannigData"), GetLocalized("Attention"), System.Windows.Forms.MessageBoxButtons.YesNo, System.Windows.Forms.MessageBoxIcon.Question) == System.Windows.Forms.DialogResult.Yes) { BuildResponse(); if (_response != null) { #if DEBUG int iCountIds = (_response.DeletedIds != null) ? _response.DeletedIds.Length : 0; int iCountEntities = (_response.ModifiedEntity != null) ? _response.ModifiedEntity.Length : 0; int iCountNewAbsence = (_response.NewAbsences != null) ? _response.NewAbsences.Length : 0; string s = String.Format(" ids-{0}, modified - {1}, new absences - {2}", iCountIds, iCountEntities, iCountNewAbsence); InfoMessage(s); #endif AbsencePlanningResponse new_response = ClientEnvironment.EmployeeService.EmployeeTimeService.SaveAbsencePlanning(_response); if (new_response != null) { SyncResponses(new_response); } _response = null; Modified = false; } } } }