/// <summary> /// Gets the day types. /// </summary> /// <param name="schedulePeriodId">The schedule period id.</param> /// <returns></returns> public OperationListResponse<BaseIdNameDto> GetDayTypes(int schedulePeriodId) { var response = new OperationListResponse<BaseIdNameDto>(); try { var unitOfWork = SWKM.Setup.IoC.Resolve<UnitOfWork>(); var schedulePeriod = unitOfWork.SchedulePeriods.FindBy(u => u.ID == schedulePeriodId).SingleOrDefault(); if (schedulePeriod == null) { response.Successful = false; response.ErrorMessage = "Nie ma okresu roskładu jazdy o takim identyfikatorze."; return response; } var dayTypes = unitOfWork.DayTypes.FindBy(u => u.DELETEDDATE == null && u.DAYTYPETEMPLATEDAYTYPE.Any(d => d.DAYTYPETEMPLATEID == schedulePeriod.DAYTYPETEMPLATEID)); response.Objects = AutoMapper.Mapper.Map<IList<DAYTYPE>, IList<BaseIdNameDto>>(dayTypes.ToList()); response.Successful = true; } catch (Exception e) { SWKM.Setup.Logger.Instance.Log.Error("Error occurred!", e); response.Successful = false; response.ErrorMessage = "Wystapił nie oczekiwany błąd przy wczytywaniu typów dni."; } return response; }
/// <summary> /// Gets the day types. /// </summary> /// <returns></returns> public OperationListResponse<DayTypeTemplateListDto> GetDayTypes() { var response = new OperationListResponse<DayTypeTemplateListDto>(); try { var unitOfWork = SWKM.Setup.IoC.Resolve<UnitOfWork>(); var dayTypes = unitOfWork.DayTypes.FindBy(u => u.DELETEDDATE == null); response.Objects = AutoMapper.Mapper.Map<IList<DAYTYPE>, IList<DayTypeTemplateListDto>>(dayTypes.ToList()); response.Successful = true; } catch (Exception e) { SWKM.Setup.Logger.Instance.Log.Error("Error occurred!", e); response.Successful = false; response.ErrorMessage = "Wystapił nie oczekiwany błąd przy wczytywaniu typów dni."; } return response; }
/// <summary> /// Gets the vehicles. /// </summary> /// <param name="showDeleted">if set to <c>true</c> [show deleted].</param> /// <returns></returns> public OperationListResponse<BaseIdNameDto> GetVehicles(bool showDeleted = false) { var response = new OperationListResponse<BaseIdNameDto>(); try { var unitOfWork = SWKM.Setup.IoC.Resolve<SWKM.DAL.UnitOfWork>(); var vehicles = unitOfWork.Vehicles.FindBy(u => u.ISAVAILABLE && (u.DELETEDDATE == null || showDeleted)); response.Objects = AutoMapper.Mapper.Map<IList<VEHICLE>, IList<BaseIdNameDto>>(vehicles.ToList()); response.Successful = true; } catch (Exception e) { SWKM.Setup.Logger.Instance.Log.Error("Error occurred!", e); response.Successful = false; response.ErrorMessage = "Wystapił nie oczekiwany błąd przy wczytywaniu pojazdów."; } return response; }
/// <summary> /// Gets all exceptions. /// </summary> /// <returns></returns> public OperationListResponse<BaseIdNameDto> GetAllExceptions() { var response = new OperationListResponse<BaseIdNameDto>(); try { var unitOfWork = SWKM.Setup.IoC.Resolve<UnitOfWork>(); var exceptions = unitOfWork.Exceptions.FindAll().OrderBy(s => s.NAME).ToList(); response.Objects = AutoMapper.Mapper.Map<IList<SWKM.DAL.EXCEPTION>, IList<BaseIdNameDto>>(exceptions); ; response.Successful = true; } catch (Exception e) { SWKM.Setup.Logger.Instance.Log.Error("Error occurred!", e); response.Successful = false; response.ErrorMessage = "Wystapił błąd przy wczytywaniu listy wyjątków."; } return response; }
/// <summary> /// Gets the line exceptions. /// </summary> /// <param name="lineId">The line id.</param> /// <returns></returns> public OperationListResponse<SelectExceptionDto> GetAllLineExceptions(int lineId) { var response = new OperationListResponse<SelectExceptionDto>(); try { var unitOfWork = SWKM.Setup.IoC.Resolve<UnitOfWork>(); var exceptions = unitOfWork.Exceptions.FindAll().OrderBy(s => s.NAME).ToList(); var exceptionsDto = AutoMapper.Mapper.Map<IList<SWKM.DAL.EXCEPTION>, IList<SelectExceptionDto>>(exceptions); var selectedExceptions = exceptions.Where(e => e.LINEEXCEPTION.Any(le => le.LINEID == lineId)).ToList(); // Oznaczenie wybranych wyjątków. if(lineId != 0) { foreach (var exception in exceptionsDto) { if (selectedExceptions.Any(se => se.ID == exception.ID)) { exception.ISSELECTED = true; } } } response.Objects = exceptionsDto; response.Successful = true; } catch (Exception e) { SWKM.Setup.Logger.Instance.Log.Error("Error occurred!", e); response.Successful = false; response.ErrorMessage = "Wystapił błąd przy wczytywaniu listy wyjątków."; } return response; }
/// <summary> /// Gets the stations. /// </summary> /// <param name="scheduleId">The schedule id.</param> /// <returns></returns> public OperationListResponse<SWKM.BLL.Messages.Planner.StationDto> GetStations(int scheduleId) { var response = new OperationListResponse<SWKM.BLL.Messages.Planner.StationDto>(); try { var unitOfWork = SWKM.Setup.IoC.Resolve<UnitOfWork>(); var stations = unitOfWork.Stations.FindBy(u => u.ROUTE.Any(r => r.SCHEDULEPERIODID == scheduleId && r.DELETEDDATE == null) && u.ISAVAILABLE == true && u.DELETEDDATE == null).OrderBy(s => s.NAME); response.Objects = AutoMapper.Mapper.Map<IList<STATION>, IList<SWKM.BLL.Messages.Planner.StationDto>>(stations.ToList()); response.Successful = true; } catch (Exception e) { SWKM.Setup.Logger.Instance.Log.Error("Error occurred!", e); response.Successful = false; response.ErrorMessage = "Wystapił błąd przy wczytywaniu listy przystanków."; } return response; }
/// <summary> /// Gets all stations. /// </summary> /// <returns></returns> public OperationListResponse<STATION> GetAllStations() { var response = new OperationListResponse<STATION>(); try { var unitOfWork = SWKM.Setup.IoC.Resolve<UnitOfWork>(); var stations = unitOfWork.Stations.FindBy(u => u.DELETEDDATE == null).OrderBy(s => s.NAME); response.Objects = stations.ToList(); response.Successful = true; } catch (Exception e) { SWKM.Setup.Logger.Instance.Log.Error("Error occurred!", e); response.Successful = false; response.ErrorMessage = "Wystapił nie oczekiwany błąd."; } return response; }
/// <summary> /// Gets the plan courses to execution. /// </summary> /// <param name="lineId">The line id.</param> /// <param name="showExecuted">if set to <c>true</c> [show executed].</param> /// <returns></returns> public OperationListResponse<SWKM.BLL.Dto.PlanCourseListDto> GetPlanCoursesToExecution(int lineId, bool showExecuted = false) { var response = new OperationListResponse<SWKM.BLL.Dto.PlanCourseListDto>(); try { var unitOfWork = SWKM.Setup.IoC.Resolve<UnitOfWork>(); IQueryable<PLANCOURSE> courses; if (showExecuted) { // Pokazuje tylko kursy wykonane courses = unitOfWork.PlanCourses.FindBy(c => c.EXECUTIONDRIVERID.HasValue || c.EXECUTIONVEHICLEID.HasValue); } else { // Pokazuje tylko kursy nie wykonane courses = unitOfWork.PlanCourses.FindBy(c => c.EXECUTIONDATE == null && c.FAILUREKEY == null); } // Filtorwanie kursów zależne od filtra if (lineId != 0) { courses = courses.Where(c => c.COURSE.LINEID == lineId); } var lista = courses.ToList(); lista = lista.Where(p => p.PLANDATE.Date == DateTime.Now.Date || p.PLANDATE.Date == DateTime.Now.AddDays(-1).Date).ToList(); response.Objects = AutoMapper.Mapper.Map<IList<PLANCOURSE>, IList<SWKM.BLL.Dto.PlanCourseListDto>>(lista); response.Successful = true; } catch (Exception e) { SWKM.Setup.Logger.Instance.Log.Error("Error occurred!", e); response.Successful = false; response.ErrorMessage = "Wystapił błąd przy wczytywaniu listy planowanych kursów."; } return response; }
/// <summary> /// Gets the courses. /// </summary> /// <param name="request">The request.</param> /// <returns></returns> public OperationListResponse<SWKM.BLL.Dto.CourseListDto> GetCourses(CourseListRequest request) { var response = new OperationListResponse<SWKM.BLL.Dto.CourseListDto>(); try { var unitOfWork = SWKM.Setup.IoC.Resolve<UnitOfWork>(); // pobiera tylko te krusy które ne należą do usuniętych lini var courses = unitOfWork.Courses.FindBy(c => c.LINE.DELETEDDATE == null); // Filtorwanie kursów zależne od filtra if (request.SchedulePeriodId != 0) { courses = courses.Where(c => c.SCHEDULEPERIODID == request.SchedulePeriodId); } if (request.LineId != 0) { courses = courses.Where(c => c.LINEID == request.LineId); } if (request.DayTypeId != 0) { courses = courses.Where(c => c.DAYTYPEID.HasValue ? c.DAYTYPEID == request.DayTypeId : false); } if (request.ExceptionId != 0) { courses = courses.Where(c => c.EXCEPTIONID.HasValue ? c.EXCEPTIONID == request.ExceptionId : false); } response.Objects = AutoMapper.Mapper.Map<IList<COURSE>, IList<SWKM.BLL.Dto.CourseListDto>> (courses.ToList()); response.Successful = true; } catch (Exception e) { SWKM.Setup.Logger.Instance.Log.Error("Error occurred!", e); response.Successful = false; response.ErrorMessage = "Wystapił błąd przy wczytywaniu listy kursów."; } return response; }
/// <summary> /// Gets the course. /// </summary> /// <param name="lineId">The line id.</param> /// <param name="courseId">The course id.</param> /// <returns></returns> public OperationListResponse<DeparatureDto> GetCourseDeparatures(int lineId, int periodId, int courseId = 0) { var response = new OperationListResponse<DeparatureDto>(); try { var unitOfWork = SWKM.Setup.IoC.Resolve<UnitOfWork>(); if (courseId == 0) { var routes = unitOfWork.Routes.FindBy(u => u.LINEID == lineId && u.DELETEDDATE == null && u.SCHEDULEPERIODID == periodId); response.Objects = Mapper.Map<IList<ROUTE>, IList<DeparatureDto>>(routes.ToList()); } else { var deparatures = unitOfWork.Departures.FindBy(u => u.COURSEID == courseId && u.ROUTE.DELETEDDATE == null); response.Objects = Mapper.Map<IList<DEPARTURE>, IList<DeparatureDto>>(deparatures.ToList()); } response.Successful = true; } catch (Exception e) { SWKM.Setup.Logger.Instance.Log.Error("Error occurred!", e); response.Successful = false; response.ErrorMessage = "Wystapił błąd przy wczytywaniu trasy."; } return response; }
/// <summary> /// Gets the lines. /// </summary> /// <param name="schedulePeriodId">The schedule period id.</param> /// <returns></returns> public OperationListResponse<BaseIdNameDto> GetLines(int schedulePeriodId) { var response = new OperationListResponse<BaseIdNameDto>(); try { var unitOfWork = SWKM.Setup.IoC.Resolve<UnitOfWork>(); var lines = unitOfWork.Lines.FindBy(u => u.DELETEDDATE == null && u.ROUTE.Any(r => r.SCHEDULEPERIODID == schedulePeriodId && r.DELETEDDATE == null)); response.Objects = AutoMapper.Mapper.Map<IList<LINE>, IList<BaseIdNameDto>>(lines.ToList()); response.Successful = true; } catch (Exception e) { SWKM.Setup.Logger.Instance.Log.Error("Error occurred!", e); response.Successful = false; response.ErrorMessage = "Wystapił nie oczekiwany błąd przy wczytywaniu lini."; } return response; }
/// <summary> /// Gets the schedule periods. /// </summary> /// <param name="showHistorical">if set to <c>true</c> [show historical].</param> /// <returns></returns> public OperationListResponse<SCHEDULEPERIOD> GetSchedulePeriods(bool showHistorical = false) { var response = new OperationListResponse<SCHEDULEPERIOD>(); try { var unitOfWork = SWKM.Setup.IoC.Resolve<UnitOfWork>(); var schedulePeriods = unitOfWork.SchedulePeriods.FindBy(s => showHistorical || s.VALIDFROM > DateTime.Now).OrderBy(s => s.VALIDFROM); response.Objects = schedulePeriods.ToList(); response.Successful = true; } catch (Exception e) { SWKM.Setup.Logger.Instance.Log.Error("Error occurred!", e); response.Successful = false; response.ErrorMessage = "Wystapił błąd przy wczytywaniu listy okresów."; } return response; }