public string Put(int id, [FromBody] Timetable timetable) { SessionFactory sessionFactory = new SessionFactory(); SessionsTable <Session> instanceSession = (SessionsTable <Session>)sessionFactory.GetSessionInstance(); TimetableFactory timetableFactory = new TimetableFactory(); TimetableTable <Timetable> instanceTimetable = (TimetableTable <Timetable>)timetableFactory.GetTimetableInstance(); var list = Request.Headers.ToList(); var token = list.Where(a => a.Key == "token")?.FirstOrDefault().Value.FirstOrDefault()?.Replace("\"", string.Empty); if (token == null) { return("NOT LOGED"); } var dispatcher = instanceSession.SelectDispatcherSession(token); var driver = instanceSession.SelectDriverSession(token); var manager = instanceSession.SelectManagerSession(token); if (dispatcher == null && driver == null && manager == null) { return("NOT EXISTING USER"); } else if (timetable == null) { return("NO OBJECT"); } instanceTimetable.Update(timetable); return("OK"); }
public TimetableDTO Get(int id) { TimetableFactory timetableFactory = new TimetableFactory(); TimetableTable <Timetable> instanceTimetable = (TimetableTable <Timetable>)timetableFactory.GetTimetableInstance(); return(new TimetableDTO(instanceTimetable.Select(id))); }
public IEnumerable <TimetableDTO> GetDriversJourneys() { SessionFactory sessionFactory = new SessionFactory(); var instanceSession = sessionFactory.GetSessionInstance(); var list = Request.Headers.ToList(); var token = list.Where(a => a.Key == "token")?.FirstOrDefault().Value.FirstOrDefault()?.Replace("\"", string.Empty); if (token == null) { return(new List <TimetableDTO>()); } var driver = instanceSession.SelectDriverSession(token); if (driver == null) { return(new List <TimetableDTO>()); } TimetableFactory timetableFactory = new TimetableFactory(); TimetableTable <Timetable> instanceTimetable = (TimetableTable <Timetable>)timetableFactory.GetTimetableInstance(); var listTimetables = instanceTimetable.SelectDrivers(driver.id); var listDTO = new List <TimetableDTO>(); foreach (var item in listTimetables) { listDTO.Add(new TimetableDTO(item)); } return(listDTO); }
public IEnumerable <TimetableDTO> Get() { TimetableFactory timetableFactory = new TimetableFactory(); TimetableTable <Timetable> instanceTimetable = (TimetableTable <Timetable>)timetableFactory.GetTimetableInstance(); var listDTO = new List <TimetableDTO>(); var list = instanceTimetable.Select(); foreach (var item in list) { listDTO.Add(new TimetableDTO(item)); } return(listDTO); }
/// <summary> /// Select the record for a name. /// </summary> //public Failure SelectForName(string pName, Database pDb = null) //{ // Database db; // if (pDb == null) // { // db = new Database(); // db.Connect(); // } // else // { // db = pDb; // } // SqlCommand command = db.CreateCommand(SQL_SELECT_NAME); // command.Parameters.AddWithValue("@name", pName); // SqlDataReader reader = db.Select(command); // Collection<Failure> failures = Read(reader); // Failure v = null; // if (failures.Count == 1) // { // v = failures[0]; // } // reader.Close(); // if (pDb == null) // { // db.Close(); // } // return v; //} private Collection <T> Read(SqlDataReader reader) { TimetableFactory timetableFactory = new TimetableFactory(); TimetableTable <Timetable> instance = (TimetableTable <Timetable>)timetableFactory.GetTimetableInstance(); Collection <T> failures = new Collection <T>(); while (reader.Read()) { Failure failure = new Failure(); int i = -1; failure.id = reader.GetInt32(++i); failure.created = reader.GetDateTime(++i); failure.type = (FailureType)reader.GetInt32(++i); failure.place = reader.GetString(++i); failure.severity = reader.GetInt32(++i); failure.message = reader.GetString(++i); failure.resolved = reader.IsDBNull(++i) == true ? (DateTime?)null : reader.GetDateTime(i); failure.timetable = instance.Select(reader.GetInt32(++i)); failures.Add((T)failure); } return(failures); }
public Collection <T> Select() { TimetableFactory timetableFactory = new TimetableFactory(); TimetableTable <Timetable> instanceTimetable = (TimetableTable <Timetable>)timetableFactory.GetTimetableInstance(); XDocument xDoc = XDocument.Load(Configuration.XMLFILEPATH); Collection <T> failures = new Collection <T>(); List <XElement> elements = xDoc.Descendants("Failures").Descendants("Failure").ToList(); foreach (var element in elements) { Failure failure = new Failure(); failure.id = int.Parse(element.Attribute("id").Value); failure.created = DateTime.Parse(element.Attribute("created").Value); failure.type = (FailureType)int.Parse(element.Attribute("type").Value); failure.place = element.Attribute("place").Value; failure.severity = int.Parse(element.Attribute("severity").Value); failure.message = element.Attribute("message").Value; failure.resolved = failure.created = DateTime.Parse(element.Attribute("resolved").Value); failure.timetable = instanceTimetable.Select(int.Parse(element.Attribute("timetableId").Value)); failures.Add((T)failure); } return(failures); }