/// <summary> /// Deletes the course. /// </summary> /// <param name="id">The id.</param> /// <returns></returns> public BaseOperationResponse DeleteCourse(int id) { var response = new BaseOperationResponse(); try { var unitOfWork = SWKM.Setup.IoC.Resolve<UnitOfWork>(); var course = unitOfWork.Courses.FindBy(u => u.ID == id).SingleOrDefault(); if (course == null) { response.Successful = false; response.ErrorMessage = "Nie ma kursu o takim identyfikatorze."; return response; } unitOfWork.Courses.Delete(course); unitOfWork.Save(); 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 usuwaniu kursu."; } return response; }
/// <summary> /// Deletes the station. /// </summary> /// <param name="id">The id.</param> /// <returns></returns> public BaseOperationResponse DeleteStation(int id) { var response = new BaseOperationResponse(); try { var unitOfWork = SWKM.Setup.IoC.Resolve<UnitOfWork>(); var station = unitOfWork.Stations.FindBy(u => u.ID == id).SingleOrDefault(); if (station == null) { response.Successful = false; response.ErrorMessage = "Nie ma stacji o takim identyfikatorze."; return response; } if (station.ROUTE.Where(r => r.DELETEDDATE != null).Any()) { response.Successful = false; response.ErrorMessage = "Nie mozna usunac stacji która ma powiązną trasę."; return response; } station.DELETEDDATE = DateTime.Now; unitOfWork.Save(); 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> /// Checks the station schedule parameters. /// </summary> /// <param name="scheduleId">The schedule id.</param> /// <param name="stationId">The station id.</param> /// <param name="lineId">The line id.</param> /// <returns></returns> public BaseOperationResponse CheckStationScheduleParameters(int scheduleId, int stationId) { var response = new BaseOperationResponse(); try { var unitOfWork = SWKM.Setup.IoC.Resolve<SWKM.DAL.UnitOfWork>(); var route = unitOfWork.Routes.FindBy(u => u.SCHEDULEPERIODID == scheduleId && u.STATIONID == stationId && u.DELETEDDATE == null); if (route.Any() == false) { response.Successful = false; response.ErrorMessage = "Nie ma utworzonej trasy dla podanych parametrów."; return response; } else if (route.Any(r => r.DEPARTURE.Any()) == false) { response.Successful = false; response.ErrorMessage = "Nie ma utworzonego rozkładu dla tego przystanku."; return response; } 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> /// Edits the course. /// </summary> /// <param name="request">The request.</param> /// <returns></returns> public BaseOperationResponse EditCourse(CourseDto request) { var response = new BaseOperationResponse(); try { var unitOfWork = SWKM.Setup.IoC.Resolve<UnitOfWork>(); COURSE course; if (request.ID == 0) { // Dodanie kursu course = AutoMapper.Mapper.Map<CourseDto, COURSE>(request); unitOfWork.Courses.Add(course); unitOfWork.Save(); foreach (var deparature in request.Deparatures) { unitOfWork.Departures.Add( new DEPARTURE() { ROUTEID = deparature.RouteId, COURSEID = course.ID, TIME = deparature.Time }); } } else { foreach (var deparature in request.Deparatures) { var entity = unitOfWork.Departures.FindBy(d => d.ID == deparature.DeparatureId).SingleOrDefault(); entity.TIME = deparature.Time; } } unitOfWork.Save(); 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 edytowaniu kursu."; } return response; }
/// <summary> /// Adds the station. /// </summary> /// <param name="name">The name.</param> /// <param name="adres">The adres.</param> /// <param name="isAvailable">if set to <c>true</c> [is available].</param> /// <returns></returns> public BaseOperationResponse AddStation(string name, string adres, bool isAvailable) { var response = new BaseOperationResponse(); try { var unitOfWork = SWKM.Setup.IoC.Resolve<UnitOfWork>(); var station = unitOfWork.Stations.FindBy(u => u.NAME == name && u.DELETEDDATE == null).SingleOrDefault(); if (station != null) { response.Successful = false; response.ErrorMessage = "Stacja o takiej nazwie już istnieje w systemie."; return response; } var newStation = new STATION() { NAME = name, ADDRESS = adres, ISAVAILABLE = isAvailable }; unitOfWork.Stations.Add(newStation); unitOfWork.Save(); 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> /// Edits the station. /// </summary> /// <param name="id">The id.</param> /// <param name="name">The name.</param> /// <param name="adres">The adres.</param> /// <param name="isAvailable">if set to <c>true</c> [is available].</param> /// <returns></returns> public BaseOperationResponse EditStation(int id, string name, string adres, bool isAvailable) { var response = new BaseOperationResponse(); try { var unitOfWork = SWKM.Setup.IoC.Resolve<UnitOfWork>(); var station = unitOfWork.Stations.FindBy(u => u.NAME == name && u.DELETEDDATE == null).SingleOrDefault(); if (station != null) { response.Successful = false; response.ErrorMessage = "Stacja o takiej nazwie już istnieje w systemie."; return response; } station = unitOfWork.Stations.FindBy(u => u.ID == id).SingleOrDefault(); if (station == null) { response.Successful = false; response.ErrorMessage = "Nie ma stacji o takim identyfikatorze."; return response; } station.NAME = name; station.ADDRESS = adres; station.ISAVAILABLE = isAvailable; unitOfWork.Save(); 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> /// Saves the plan courses. /// </summary> /// <param name="planCourseList">The plan course list.</param> /// <returns></returns> public BaseOperationResponse SavePlanCourses(IList<PlanCourseListDto> planCourseList) { var response = new BaseOperationResponse(); try { var unitOfWork = SWKM.Setup.IoC.Resolve<UnitOfWork>(); foreach (var planCourse in planCourseList) { var courseEntity = unitOfWork.PlanCourses.FindBy(p => p.ID == planCourse.ID).FirstOrDefault(); if (courseEntity != null) { courseEntity.PLANVEHICLEID = planCourse.VEHICLEID == 0 ? (int?)null : planCourse.VEHICLEID; courseEntity.PLANDRIVERID = planCourse.DRIVERID == 0 ? (int?)null : planCourse.DRIVERID; } } unitOfWork.Save(); 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 zapisywaniu planowanych kursów."; } return response; }
/// <summary> /// Adds the schedule period. /// </summary> /// <param name="validFrom">The valid from.</param> /// <param name="validTo">The valid to.</param> /// <param name="planningPeriod">The planning period.</param> /// <param name="dayTypeTemplateId">The day type template id.</param> /// <returns></returns> public BaseOperationResponse AddSchedulePeriod(DateTime validFrom, DateTime? validTo, int planningPeriod, int dayTypeTemplateId) { var response = new BaseOperationResponse(); try { var unitOfWork = SWKM.Setup.IoC.Resolve<UnitOfWork>(); var dayTypeTemplate = unitOfWork.DayTypeTemplates.FindBy(u => u.ID == dayTypeTemplateId).SingleOrDefault(); if (dayTypeTemplate == null) { response.Successful = false; response.ErrorMessage = "Wybrany szablon typu dnia nie istnieje."; return response; } if (unitOfWork.SchedulePeriods.FindBy(s => s.VALIDFROM > validFrom).Any() && validTo == null) { response.Successful = false; response.ErrorMessage = "Musisz wypełnić pole \"Obowiązuje do\" ponieważ istnieją okresy planowane na późniejszy termin!"; return response; } var lastShedulePeriod = unitOfWork.SchedulePeriods.FindBy(s => s.VALIDFROM > DateTime.Now).OrderByDescending(o => o.VALIDFROM).FirstOrDefault(); // Sprawdzenie czy ostatni okres ma wypełnioną datę do jeżeli nie do jest uzupełniana if (lastShedulePeriod != null && lastShedulePeriod.VALIDTO == null) { lastShedulePeriod.VALIDTO = validFrom.AddDays(-1.0); } // Tymczosowe !!!!!!!!!!!!!! var listaDoDebug = unitOfWork.SchedulePeriods.FindAll().ToList(); var test = listaDoDebug.Where(u => (u.VALIDFROM <= validFrom && (u.VALIDTO == null ? true : (u.VALIDTO.Value >= validFrom))) || (validTo == null ? (validFrom < u.VALIDFROM) : (u.VALIDFROM <= validTo && (u.VALIDTO == null ? true : (u.VALIDTO.Value >= validTo))))).ToList(); // Sprawdzenie czy wyrnay okres nie nachodzi na inny okres if (unitOfWork.SchedulePeriods .FindBy(u => (u.VALIDFROM <= validFrom && (u.VALIDTO == null ? true : (u.VALIDTO.Value >= validFrom))) || (validTo == null ? (validFrom < u.VALIDFROM) : (u.VALIDFROM <= validTo && (u.VALIDTO == null ? true : (u.VALIDTO.Value >= validTo))))).Any()) { response.Successful = false; response.ErrorMessage = "Przedział czasu nakłada się na istniejący planowany okres."; return response; } var newShedulePeriod = new SCHEDULEPERIOD() { VALIDFROM = validFrom.Date, VALIDTO = validTo, PLANNINGPERIOD = planningPeriod, DAYTYPETEMPLATEID = dayTypeTemplateId, PLANNINGDATE = validFrom.Date }; unitOfWork.SchedulePeriods.Add(newShedulePeriod); unitOfWork.Save(); 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> /// Deletes the day type template. /// </summary> /// <param name="id">The id.</param> /// <returns></returns> public BaseOperationResponse DeleteDayTypeTemplate(int id) { var response = new BaseOperationResponse(); try { var unitOfWork = SWKM.Setup.IoC.Resolve<UnitOfWork>(); var dayTypeTemplate = unitOfWork.DayTypeTemplates.FindBy(u => u.ID == id).SingleOrDefault(); if (dayTypeTemplate == null) { response.Successful = false; response.ErrorMessage = "Nie ma szablonu o takim identyfikatorze."; return response; } if (dayTypeTemplate.SCHEDULEPERIOD.Where(s => s.VALIDFROM > DateTime.Now).Any()) { response.Successful = false; response.ErrorMessage = "Nie mozna usunąć tego szablonu ponieważ ma zaplanowane okresy rozkładu jazdy!."; return response; } dayTypeTemplate.DELETEDDATE = DateTime.Now; unitOfWork.Save(); 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 usuwaniu szablonu."; } return response; }
/// <summary> /// Executes the plan course. /// </summary> /// <param name="planCourseList">The plan course list.</param> /// <returns></returns> public BaseOperationResponse ExecutePlanCourse(ExecuteCourseDto executeCourseDto) { var response = new BaseOperationResponse(); try { var unitOfWork = SWKM.Setup.IoC.Resolve<UnitOfWork>(); var planCourse = unitOfWork.PlanCourses.FindBy(u => u.ID == executeCourseDto.ID).FirstOrDefault(); if (planCourse == null) { response.Successful = false; response.ErrorMessage = "Nie ma planowanego kursu o takim identyfikatorze."; return response; } planCourse.EXECUTIONDATE = executeCourseDto.EXECUTIONDATE; planCourse.FAILUREKEY = executeCourseDto.FAILUREKEY; planCourse.DESCRIPTION = executeCourseDto.DESCRIPTION; planCourse.EXECUTIONDRIVERID = executeCourseDto.EXECUTIONDRIVERID; planCourse.EXECUTIONVEHICLEID = executeCourseDto.EXECUTIONVEHICLEID; unitOfWork.Save(); 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 zapisywaniu planowanych kursów."; } return response; }
/// <summary> /// Deletes the line. /// </summary> /// <param name="id">The id.</param> /// <returns></returns> public BaseOperationResponse DeleteLine(int id) { var response = new BaseOperationResponse(); try { var unitOfWork = SWKM.Setup.IoC.Resolve<UnitOfWork>(); var line = unitOfWork.Lines.FindBy(u => u.ID == id).SingleOrDefault(); if (line == null) { response.Successful = false; response.ErrorMessage = "Nie ma lini o takim identyfikatorze."; return response; } if (line.COURSE.Where(c => c.SCHEDULEPERIOD.VALIDFROM <= DateTime.Now && (c.SCHEDULEPERIOD.VALIDTO.HasValue ? c.SCHEDULEPERIOD.VALIDTO > DateTime.Now : true)).Any()) { response.Successful = false; response.ErrorMessage = "Nie można usunąć lini która ma kursy w aktualnym okresie rozkładu jazdy."; return response; } foreach (var route in line.ROUTE) { route.DELETEDDATE = DateTime.Now; } line.DELETEDDATE = DateTime.Now; unitOfWork.Save(); 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 usuwaniu lini."; } return response; }
/// <summary> /// Adds the line. /// </summary> /// <param name="line">The line.</param> /// <returns></returns> public BaseOperationResponse AddLine(EditLineDto request) { var response = new BaseOperationResponse(); try { var unitOfWork = SWKM.Setup.IoC.Resolve<UnitOfWork>(); var existingLine = unitOfWork.Lines.FindBy(u => u.NAME == request.NAME).SingleOrDefault(); if (existingLine != null) { response.Successful = false; response.ErrorMessage = "Linia o takiej nazwie już istnieje."; return response; } var newline = new LINE() { NAME = request.NAME }; unitOfWork.Lines.Add(newline); unitOfWork.Save(); newline = unitOfWork.Lines.FindBy(u => u.NAME == newline.NAME && u.DELETEDDATE == null).SingleOrDefault(); foreach (var station in request.SelectedStationsList) { var newRoute = new ROUTE() { Order = station.Order, DIRECTIONHEADLINE = station.DIRECTIONHEADLINE, LINEID = newline.ID, STATIONID = station.ID, SCHEDULEPERIODID = station.SchedulePeriodId }; unitOfWork.Routes.Add(newRoute); } foreach (var exception in request.SelectedExceptionList) { var newException = new LINEEXCEPTION() { LINEID = newline.ID, EXCEPTIONID = exception.ID }; unitOfWork.LineExceptions.Add(newException); } unitOfWork.Save(); 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 dodawaniu lini."; } return response; }
/// <summary> /// Edits the line. /// </summary> /// <param name="request">The request.</param> /// <returns></returns> public BaseOperationResponse EditLine(EditLineDto request) { var response = new BaseOperationResponse(); try { var unitOfWork = SWKM.Setup.IoC.Resolve<UnitOfWork>(); var existingLine = unitOfWork.Lines.FindBy(u => u.NAME == request.NAME && u.ID != request.ID).SingleOrDefault(); if (existingLine != null) { response.Successful = false; response.ErrorMessage = "Linia o takiej nazwie już istnieje."; return response; } // Sprawdzenie czy dana linia istnieje existingLine = unitOfWork.Lines.FindBy(u => u.ID == request.ID).SingleOrDefault(); if (existingLine == null) { response.Successful = false; response.ErrorMessage = "Nie ma lini o takim identyfikatorze."; return response; } // Aktualizacja podstawowych kolumn existingLine.NAME = request.NAME; // Aktualizacja TRAS // Wybranie wszystkich tras które są powiązane z daną linią var toDelete = unitOfWork.Routes.FindBy(dt => dt.LINEID == request.ID && dt.DELETEDDATE == null).ToList(); // Wybranie tras do usunięcia. // Każda trasę powiązana z linia sprawdza się czy zawiera sie w wybranych trasach // Jeżeli nie do jest dodawana do listy do usunięcia toDelete = toDelete.Where(l => !request.SelectedStationsList.Any(d => d.ID == l.STATIONID)).ToList(); // SOftDelete każdej trasy nie wybranej foreach (var delete in toDelete) { delete.DELETEDDATE = DateTime.Now; } // Wybranie tras które są przypisane do lini var routes = unitOfWork.Routes.FindBy(l => l.LINEID == request.ID).ToList(); // Aktualizacja każdej trasy foreach (var station in request.SelectedStationsList) { var findedRoute = routes.Where(r => r.STATIONID == station.ID && r.LINEID == request.ID && r.DELETEDDATE == null && r.SCHEDULEPERIODID == station.SchedulePeriodId).SingleOrDefault(); if (findedRoute == null) { var newRoute = new ROUTE() { STATIONID = station.ID, LINEID = request.ID, Order = station.Order, DIRECTIONHEADLINE = station.DIRECTIONHEADLINE, SCHEDULEPERIODID = station.SchedulePeriodId }; unitOfWork.Routes.Add(newRoute); } else { findedRoute.Order = station.Order; findedRoute.DIRECTIONHEADLINE = station.DIRECTIONHEADLINE; } } // Aktualizacja WYJĄKÓW // Wybranie wszystkich wyjątków które są powiązane z daną linią var exceptionToDelete = unitOfWork.LineExceptions.FindBy(e => e.LINEID == request.ID).ToList(); // Wybranie wyjątków do usunięcia. exceptionToDelete = exceptionToDelete.Where(e => !request.SelectedExceptionList.Any(s => s.ID == e.EXCEPTIONID)).ToList(); // usunięcie każdego wyjątku nie wybranego foreach (var delete in exceptionToDelete) { unitOfWork.LineExceptions.Delete(delete); } // Wybranie wyjątków które są przypisane do lini var exceptions = unitOfWork.LineExceptions.FindBy(l => l.LINEID == request.ID).ToList(); // Aktualizacja każdego wyjątku foreach (var exception in request.SelectedExceptionList) { var findedException = exceptions.Where(r => r.EXCEPTIONID == exception.ID).SingleOrDefault(); if (findedException == null) { var newException = new LINEEXCEPTION() { EXCEPTIONID = exception.ID, LINEID = request.ID }; unitOfWork.LineExceptions.Add(newException); } } unitOfWork.Save(); 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 edytowaniu lini."; } return response; }
/// <summary> /// Deletes the schedule period. /// </summary> /// <param name="id">The id.</param> /// <returns></returns> public BaseOperationResponse DeleteSchedulePeriod(int id) { var response = new BaseOperationResponse(); try { var unitOfWork = SWKM.Setup.IoC.Resolve<UnitOfWork>(); var schedulePeriod = unitOfWork.SchedulePeriods.FindBy(u => u.ID == id).SingleOrDefault(); if (schedulePeriod == null) { response.Successful = false; response.ErrorMessage = "Nie ma okresu rozkładu jazdy o takim identyfikatorze."; return response; } unitOfWork.SchedulePeriods.Delete(schedulePeriod); unitOfWork.Save(); 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> /// Edits the day type template. /// </summary> /// <param name="dayTypeTemplateId">The day type template id.</param> /// <param name="name">The name.</param> /// <param name="dayTypes">The day type templates.</param> /// <returns></returns> public BaseOperationResponse EditDayTypeTemplate(int id, string name, IList<DayTypeTemplateListDto> dayTypes) { var response = new BaseOperationResponse(); try { var unitOfWork = SWKM.Setup.IoC.Resolve<UnitOfWork>(); var dayTypeTemplate = unitOfWork.DayTypeTemplates.FindBy(u => u.NAME == name && u.DELETEDDATE == null && u.ID != id).SingleOrDefault(); if (dayTypeTemplate != null) { response.Successful = false; response.ErrorMessage = "Szablon o takiej nazwie już istnieje w systemie."; return response; } dayTypeTemplate = unitOfWork.DayTypeTemplates.FindBy(u => u.ID == id).SingleOrDefault(); if (dayTypeTemplate == null) { response.Successful = false; response.ErrorMessage = "Nie ma szablonu o takim identyfikatorze."; return response; } dayTypeTemplate.NAME = name; var toDelete = unitOfWork.DayTypeTemplateDayTypes.FindBy(dt => dt.DAYTYPETEMPLATE.ID == dayTypeTemplate.ID).ToList(); toDelete = toDelete.Where(t => !dayTypes.Any(d => d.ID == t.DAYTYPEID)).ToList(); foreach (var delete in toDelete) { unitOfWork.DayTypeTemplateDayTypes.Delete(delete); } var entityDayTypes = unitOfWork.DayTypeTemplateDayTypes.FindBy(dt => dt.DAYTYPETEMPLATE.ID == dayTypeTemplate.ID).ToList(); foreach (var dayType in dayTypes) { var findedDayType = entityDayTypes.Where(dt => dt.DAYTYPEID == dayType.ID).SingleOrDefault(); if (findedDayType == null) { var dayTypeTempDayType = new DAYTYPETEMPLATEDAYTYPE() { DAYTYPETEMPLATE = dayTypeTemplate, DAYTYPEID = dayType.ID }; unitOfWork.DayTypeTemplateDayTypes.Add(dayTypeTempDayType); } } unitOfWork.Save(); 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> /// Adds the day type template. /// </summary> /// <param name="name">The name.</param> /// <param name="dayTypeTemplates">The day type templates.</param> /// <returns></returns> public BaseOperationResponse AddDayTypeTemplate(string name, IList<DayTypeTemplateListDto> dayTypeTemplates) { var response = new BaseOperationResponse(); try { var unitOfWork = SWKM.Setup.IoC.Resolve<UnitOfWork>(); var dayTypeTemplate = unitOfWork.DayTypeTemplates.FindBy(u => u.NAME == name && u.DELETEDDATE == null).SingleOrDefault(); if (dayTypeTemplate != null) { response.Successful = false; response.ErrorMessage = "Szablon o takiej nazwie już istnieje."; return response; } var newDayTypeTemplate = new DAYTYPETEMPLATE() { NAME = name }; unitOfWork.DayTypeTemplates.Add(newDayTypeTemplate); unitOfWork.Save(); newDayTypeTemplate = unitOfWork.DayTypeTemplates.FindBy(u => u.NAME == newDayTypeTemplate.NAME && u.DELETEDDATE == null).SingleOrDefault(); //var dayTypes = new List<DAYTYPETEMPLATEDAYTYPE>(); foreach (var dayTypeFromList in dayTypeTemplates) { var dayType = unitOfWork.DayTypes.FindBy(d => d.ID == dayTypeFromList.ID).SingleOrDefault(); if (dayType != null) { var dayTypeTempDayType = new DAYTYPETEMPLATEDAYTYPE() { DAYTYPETEMPLATE = newDayTypeTemplate, DAYTYPE = dayType }; unitOfWork.DayTypeTemplateDayTypes.Add(dayTypeTempDayType); } else { response.Successful = false; response.ErrorMessage = "Wybrany typ dnia nie istnieje."; return response; } } unitOfWork.Save(); 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 dodawaniu szablonu typu dnia."; } return response; }
/// <summary> /// Plans the courses. /// </summary> /// <param name="schedulePeriodId">The schedule period id.</param> /// <returns></returns> public BaseOperationResponse PlanCourses(int schedulePeriodId) { var response = new BaseOperationResponse(); try { var unitOfWork = SWKM.Setup.IoC.Resolve<UnitOfWork>(); var period = unitOfWork.SchedulePeriods.FindBy(s => s.ID == schedulePeriodId).SingleOrDefault(); if (period == null) { response.Successful = false; response.ErrorMessage = "Nie ma okresu rozkładu jazdy o takim identyfikatorze."; return response; } for (int i = 0; i < period.PLANNINGPERIOD; i++) { var date = period.PLANNINGDATE.AddDays(i); if (period.VALIDTO.HasValue ? period.VALIDTO.Value >= date : true) { foreach (var course in period.COURSE) { if (course.DAYTYPEID.HasValue) { // Wybieramy dni tygodnia var dayOfWeek = date.DayOfWeek; var dayKey = DayWeek.DayOfWeekDictionary.First(d => d.Value.SystemDayOfWeek == date.DayOfWeek).Key; if (course.DAYTYPE.LINKDAY.Any(d => d.DAYKEY == dayKey)) { var planCourse = new PLANCOURSE() { PLANDATE = date, COURSEID = course.ID }; unitOfWork.PlanCourses.Add(planCourse); } } else { // Wybieramy wyjątki // Jeżeli data planowana znajduje się w datach wyjąku to jest dodawany jako planowany dzień if (course.EXCEPTION.DAY.Any(d => d.Date == date)) { var planCourse = new PLANCOURSE() { PLANDATE = date, COURSEID = course.ID }; unitOfWork.PlanCourses.Add(planCourse); } } } } else { break; } } period.PLANNINGDATE = period.PLANNINGDATE.AddDays(period.PLANNINGPERIOD); unitOfWork.Save(); 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 planowaniu kursów."; } return response; }
/// <summary> /// Changes the password. /// </summary> /// <param name="oldPassword">The old password.</param> /// <param name="newPassword">The new password.</param> /// <returns></returns> public BaseOperationResponse ChangePassword(string oldPassword, string newPassword) { var response = new BaseOperationResponse(); try { var unitOfWork = SWKM.Setup.IoC.Resolve<UnitOfWork>(); var user = unitOfWork.Users.FindBy(u => u.ID == this.GetUser.ID).FirstOrDefault(); if (user == null) { response.Successful = false; response.ErrorMessage = "Nie ma takie uzytkownika!"; return response; } if (user.PASSWORD == oldPassword) { user.PASSWORD = newPassword; unitOfWork.Save(); response.Successful = true; } else { response.Successful = false; response.ErrorMessage = "Nie poprawne hasło!"; } return response; } 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> /// Edits the schedule period. /// </summary> /// <param name="schedulePeriodId">The schedule period id.</param> /// <param name="validFrom">The valid from.</param> /// <param name="validTo">The valid to.</param> /// <param name="planningPeriod">The planning period.</param> /// <param name="dayTypeTemplateId">The day type template id.</param> /// <returns></returns> public BaseOperationResponse EditSchedulePeriod(int schedulePeriodId, DateTime validFrom, DateTime? validTo, int planningPeriod, int dayTypeTemplateId) { var response = new BaseOperationResponse(); try { var unitOfWork = SWKM.Setup.IoC.Resolve<UnitOfWork>(); var dayTypeTemplate = unitOfWork.DayTypeTemplates.FindBy(u => u.ID == dayTypeTemplateId).SingleOrDefault(); if (dayTypeTemplate == null) { response.Successful = false; response.ErrorMessage = "Wybrany szablon typu dnia nie istnieje."; return response; } var shedulePeriod = unitOfWork.SchedulePeriods.FindBy(s => s.ID == schedulePeriodId).SingleOrDefault(); if (shedulePeriod == null) { response.Successful = false; response.ErrorMessage = "Nie ma okresu rozkładu jazdy o takim identyfikatorze."; return response; } // Tymczosowe !!!!!!!!!!!!!! var listaDoDebug = unitOfWork.SchedulePeriods.FindAll().ToList(); var test = listaDoDebug.Where(u => (u.ID != schedulePeriodId) && ((u.VALIDFROM <= validFrom && (u.VALIDTO == null ? true : (u.VALIDTO.Value >= validFrom))) || (validTo == null ? (validFrom < u.VALIDFROM) : (u.VALIDFROM <= validTo && (u.VALIDTO == null ? true : (u.VALIDTO.Value >= validTo)))))).ToList(); // Sprawdzenie czy wyrnay okres nie nachodzi na inny okres if (unitOfWork.SchedulePeriods .FindBy(u => (u.ID != schedulePeriodId) && ((u.VALIDFROM <= validFrom && (u.VALIDTO == null ? true : (u.VALIDTO.Value >= validFrom))) || (validTo == null ? (validFrom < u.VALIDFROM) : (u.VALIDFROM <= validTo && (u.VALIDTO == null ? true : (u.VALIDTO.Value >= validTo)))))).Any()) { response.Successful = false; response.ErrorMessage = "Przedział czasu nakłada się na istniejący planowany okres."; return response; } shedulePeriod.VALIDFROM = validFrom.Date; shedulePeriod.VALIDTO = validTo; shedulePeriod.PLANNINGPERIOD = planningPeriod; shedulePeriod.DAYTYPETEMPLATEID = dayTypeTemplateId; shedulePeriod.PLANNINGDATE = validFrom.Date; unitOfWork.Save(); 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; }