internal AppointmentChangedResult AppointmentCancel(int userId, int unitId, SchedulerEvent schedulerEvent) { var dataService = new QNomyDataService(); AppointmentChangedResult result = new AppointmentChangedResult(); int processId = schedulerEvent.ProcessId; ProcessCancelCaseResults cancelResult = Process.CancelCase(processId, userId, 0); if (cancelResult.CurrentProcessId > 0) { schedulerEvent.ProcessId = cancelResult.CurrentProcessId; CustomizeData customizeData = GetCustomizeData(unitId); var calendarStages = dataService.GetClendarStages(customizeData.ConfigId); AdjustStageType(schedulerEvent, calendarStages, customizeData); result.EventData = schedulerEvent; } List <AppUser.UserStatus> okStatus = new List <AppUser.UserStatus>() { AppUser.UserStatus.Idle, AppUser.UserStatus.Unknown, AppUser.UserStatus.SignedOut }; if (!okStatus.Contains(cancelResult.UserStatus)) { throw new DataException($"Not Canceled, user status {cancelResult.UserStatus.ToString()}"); } return(result); }
public List <SchedulerEvent> GetSchedulerEvents(DateTime?from, DateTime?to, int unitId) { var result = new List <SchedulerEvent>(); var now = DateTime.Now; var dataService = new QNomyDataService(); var appointments = dataService.GetAppointments(from, to); CustomizeData customizeData = GetCustomizeData(unitId); var calendarStages = dataService.GetClendarStages(customizeData.ConfigId); var statusMapping = GetMappingCalendarStageTypeToEntityStatus(); foreach (var app in appointments) { app.CalendarStageType = statusMapping[app.CurrentEntityStatus]; int?stageId = GetStageByServiceId(app.ServiceId, app.CalendarStageType, calendarStages, customizeData); if (!stageId.HasValue) { continue; } app.StageId = stageId.Value; SchedulerEvent se = ToScheduleEvent(app); result.Add(se); } return(result); }
internal List <StageInfo> GetStages(int rootUnitId) { var dataService = new QNomyDataService(); var configId = dataService.GetConfigId(rootUnitId); List <CalendarStage> calendarStages = dataService.GetClendarStages(configId); var result = new List <StageInfo>(); foreach (var stage in calendarStages) { result.Add(new StageInfo { Key = stage.Id, Label = stage.Name }); } return(result); }
internal CustomizeData GetCustomizeData(int currentUnitId) { var result = new CustomizeData(); var dataService = new QNomyDataService(); result.UnitId = currentUnitId; result.ConfigId = dataService.GetConfigId(currentUnitId); result.NotShownServices = new List <CustomizeStageService>(); result.Stages = new List <CustomizeCalendarStage>(); List <CalendarStage> calendarStages = dataService.GetClendarStages(result.ConfigId); var services = dataService.GetServicesForUnit(currentUnitId); var stageServices = dataService.GetClendarStageServices(result.ConfigId); foreach (var stage in calendarStages) { if (stage.StageType == CalendarStageType.None) { continue; } var calendarStage = new CustomizeCalendarStage { Id = stage.Id, Name = stage.Name, StageType = stage.StageType, SortOrder = stage.SortOrder, IsServiceDefault = stage.IsServiceDefault, CalendarStageConfigId = stage.CalendarStageConfigId }; calendarStage.Services = new List <CustomizeStageService>(); result.Stages.Add(calendarStage); } CustomizeCalendarStage defaultInServiceStageForNotMappedServices = result.Stages.Find(x => x.IsServiceDefault); //can be null; foreach (var service in services) { CustomizeCalendarStage stage = null; CalendarStageService stageForService = stageServices.Find(x => x.ServiceId == service.Id); if (stageForService == null) { stage = defaultInServiceStageForNotMappedServices; } else { stage = result.Stages.Find(x => x.Id == stageForService.CalendarStageId); } if (stage != null && stage.StageType == CalendarStageType.None) { stage = null; } if (stage == null) { result.NotShownServices.Add(new CustomizeStageService() { ServiceId = service.Id, Name = service.Name, CalendarStageId = -1 }); } else { stage.Services.Add(new CustomizeStageService() { ServiceId = service.Id, Name = service.Name, CalendarStageId = stage.Id }); } } return(result); }