public string EditLine(LinePlus linePlus) { int result = 1; Line line = db.Lines.GetAll().FirstOrDefault(u => u.Number == linePlus.Number); if (line == null) { return("Line can't be changed"); } else { if (line.Number != linePlus.Number) { return("Data was modified in meantime, please try again!"); } line.Stations = new List <Station>(); if (linePlus.Stations != null) { foreach (Station s in linePlus.Stations) { var station = db.Stations.GetAll().FirstOrDefault(u => u.Name == s.Name); line.Stations.Add(station); db.Stations.Update(station); } } if (linePlus.TypeOfLine == "Town") { line.RouteType = Enums.RouteType.Town; } else if (linePlus.TypeOfLine == "Suburban") { line.RouteType = Enums.RouteType.Suburban; } db.Lines.Update(line); result = db.Complete(); if (result == 0) { return("conflict"); } else if (result == -1) { return("Data was modified in meantime, please try again!"); } } return("ok"); }
public IEnumerable <LinePlus> GetScheduleLines(string typeOfLine) { if (typeOfLine == null) { var type = db.Lines.GetAll().FirstOrDefault(u => u.RouteType == Enums.RouteType.Town); List <Line> lines = db.Lines.GetAll().ToList(); List <LinePlus> ret = new List <LinePlus>(); foreach (Line l in lines) { LinePlus lp = new LinePlus() { Number = l.Number, IDtypeOfLine = 0, TypeOfLine = type.ToString(), Stations = l.Stations }; ret.Add(lp); } return(ret); } else { RouteType type = Enums.RouteType.Town; if (typeOfLine == "Town") { type = Enums.RouteType.Town; } else if (typeOfLine == "Suburban") { type = Enums.RouteType.Suburban; } List <Line> lines = db.Lines.GetAll().ToList(); List <LinePlus> ret = new List <LinePlus>(); foreach (Line l in lines) { if (l.RouteType == type) { LinePlus lp = new LinePlus() { Number = l.Number, IDtypeOfLine = 0, TypeOfLine = type.ToString(), Stations = l.Stations }; ret.Add(lp); } } return(ret); } }
public IEnumerable <LinePlus> GetLines() { List <Line> lines = db.Lines.GetAll().ToList(); List <LinePlus> ret = new List <LinePlus>(); foreach (Line l in lines) { RouteType type = l.RouteType; //db.TypesOfLine.GetAll().FirstOrDefault(u => u.IDtypeOfLine == l.IDtypeOfLine).typeOfLine; LinePlus lp = new LinePlus() { Number = l.Number, IDtypeOfLine = 0, TypeOfLine = type.ToString(), Stations = l.Stations }; ret.Add(lp); } return(ret); }
public string AddLine(LinePlus linePlus) { Line line = db.Lines.GetAll().FirstOrDefault(u => u.Number == linePlus.Number); if (line != null) { return("Line with that number already exist"); } else { RouteType id = RouteType.Town; if (linePlus.TypeOfLine == "Town") { id = Enums.RouteType.Town; } else if (linePlus.TypeOfLine == "Suburban") { id = Enums.RouteType.Suburban; } Line newLine = new Line() { Number = linePlus.Number, RouteType = id }; newLine.Stations = new List <Station>(); foreach (Station s in linePlus.Stations) { var station = db.Stations.GetAll().FirstOrDefault(u => u.Name == s.Name); newLine.Stations.Add(station); db.Stations.Update(station); } db.Lines.Add(newLine); try { db.Complete(); } catch (Exception e) { } } return("ok"); }