/// <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; } }
/// <summary> /// Get All the Appointments for the staff based on MobileCalendarEventsDaysLookUpInPast and MobileCalendarEventsDaysLookUpInFuture /// </summary> /// <param name="StaffId"></param> /// <returns></returns> public List <Models.AppointmentModel> GetCalanderEvents(int StaffId) { try { List <Models.AppointmentModel> appointments = new List <Models.AppointmentModel>(); var mobStaff = (from a in _ctx.StaffPreferences where a.StaffId == StaffId select new { backfromCurrentDate = a.MobileCalendarEventsDaysLookUpInPast, forwardfromCurrentDate = a.MobileCalendarEventsDaysLookUpInFuture }).FirstOrDefault(); DateTime dtStart = DateTime.Now.AddDays(-(double)mobStaff.backfromCurrentDate); DateTime dtEnd = DateTime.Now.AddDays((double)mobStaff.forwardfromCurrentDate); dtEnd = dtEnd.Date.Add(new TimeSpan(23, 59, 59));// To Consider the complete Day List <Models.AppointmentModel> events = GetServiceAppointments(StaffId, dtStart, dtEnd); appointments.AddRange(events); foreach (var calevent in events) { if (calevent != null) { var briefcaseType = calevent.Service == null?CommonDBFunctions.GetGlobalCodeId("BRIEFCASETYPE", "APPOINTMENT") : CommonDBFunctions.GetGlobalCodeId("BRIEFCASETYPE", "SERVICE"); CommonFunctions <Models.AppointmentModel> .CreateUpdateBriefcase(calevent.AppointmentId, calevent, StaffId, briefcaseType); } } return(appointments); } catch (Exception ex) { Exception excep = new Exception("Exception occured in BriefcaseRepositiry.GetCalanderEvents method." + ex.Message); throw excep; } }
/// <summary> /// Retusn My Preference Data for the loggedin staff /// </summary> /// <param name="currentStaffId"></param> /// <returns></returns> public async Task <Models.StaffPreferenceModel> GetMyPreference(int currentStaffId) { try { var repo = new MobileStaffRepositiry(new SC.Data.SCMobile()); var user = await repo.FindMobileUser(currentStaffId); if (user != null) { CommonFunctions <Models.StaffPreferenceModel> .CreateUpdateBriefcase(user.StaffPreferenceId, user, currentStaffId, CommonDBFunctions.GetGlobalCodeId("BRIEFCASETYPE", "MYPREFERENCE")); } return(user); } catch (Exception ex) { Exception excep = new Exception("Exception occured in BriefcaseRepositiry.GetMyPreference method." + ex.Message); throw excep; } }