/// <summary> /// Function for differential merge /// </summary> /// <param name="briefcaseTypeId"></param> /// <param name="staffId"></param> /// <param name="briefcaseType"></param> /// <param name="newObject"></param> /// <param name="differences"></param> /// <returns></returns> public bool IsDataModified(int briefcaseTypeId, int staffId, int briefcaseType, Data.StaffPreferences newObject, out List <Difference> differences) { try { CompareLogic cl = new CompareLogic(); StaffPreferences sp = CommonFunctions <StaffPreferences> .GetBriefcase(briefcaseTypeId, staffId, briefcaseType); ComparisonResult cr = new ComparisonResult(new ComparisonConfig() { MaxDifferences = 100 }); cr = cl.Compare(newObject, sp); if (!cr.AreEqual) { differences = cr.Differences; } else { differences = null; } return(!cr.AreEqual); } catch (Exception ex) { Exception excep = new Exception("Exception occured in MobileStaffRepositiry.IsDataModified method." + ex.Message); throw excep; } }
/// <summary> /// Save MyPreference Screen Data. /// </summary> /// <param name="stf"></param> /// <param name="loggedInUser"></param> /// <returns></returns> public async Task <_SCResult <Models.StaffPreferenceModel> > Save(StaffPreferences stf, int loggedInUser) { try { var _Ce = new _SCResult <Models.StaffPreferenceModel>(); IBriefcaseRepository _repo = new BriefcaseRepositiry(new SCMobile()); List <Difference> differences = new List <Difference>(); bool modified = IsDataModified(stf.StaffPreferenceId, loggedInUser, CommonDBFunctions.GetGlobalCodeId("BRIEFCASETYPE", "MYPREFERENCE"), stf, out differences); if (modified) { var original = _scEntity.StaffPreferences .Where(s => s.StaffPreferenceId == stf.StaffPreferenceId).FirstOrDefault(); foreach (var difference in differences) { string[] changedPprts = difference.PropertyName.Split(new char[] { '.' }, StringSplitOptions.RemoveEmptyEntries); //Handled only objects which doesn't have sibling object if (string.IsNullOrEmpty(difference.ParentPropertyName)) { foreach (PropertyInfo propertyInfo in original.GetType().GetProperties()) { if (changedPprts.Contains(propertyInfo.Name)) { propertyInfo.SetValue(original, propertyInfo.GetValue(stf, null), null); } } } } _scEntity.SaveChanges(); } _Ce.SavedResult = await _repo.GetMyPreference(stf.StaffId); _Ce.LocalstoreName = "mypreference"; _Ce.UnsavedId = _Ce.SavedId = _Ce.SavedResult.StaffPreferenceId; _Ce.DeleteUnsavedChanges = true; _Ce.ShowDetails = false; _Ce.Details = null; _Ce.SavedResult = await FindMobileUser(stf.StaffId); if (stf != null) { CommonFunctions <Models.StaffPreferenceModel> .CreateUpdateBriefcase(stf.StaffPreferenceId, _Ce.SavedResult, loggedInUser, CommonDBFunctions.GetGlobalCodeId("BRIEFCASETYPE", "MYPREFERENCE")); } return(_Ce); } catch (Exception ex) { Exception excep = new Exception("Exception occured in MobileStaffRepositiry.Save method." + ex.Message); throw excep; } }