public TableAdjustment EditTrainsStaffMember(LatticeData <Employee, EmployeeRow> latticeData, EmployeeRow employeeRow) { if (string.IsNullOrEmpty(employeeRow.UserId)) { return(latticeData.Adjust(x => x .Message(LatticeMessage.User("failure", "Editing", "Can not create create new employee from here")) )); } Employee employee = _context.Employees .FirstOrDefault(x => x.UserId == employeeRow.UserId); if (employee == null) { return(latticeData.Adjust(x => x .Message(LatticeMessage.User("failure", "Editing", "Can not find employee")) )); } employee.TrainId = employeeRow.TrainId; _context.SaveChanges(); return(latticeData.Adjust(x => x .Update(employeeRow) .Message(LatticeMessage.User("success", "Editing", "Employee saved")) )); }
public TableAdjustment EditStaton(LatticeData <Station, Station> latticeData, Station stationRow) { Station station = _context.Stations .FirstOrDefault(x => x.StationId == stationRow.StationId); if (station == null) { station = new Station() { StationId = stationRow.StationId }; _context.Stations.Add(station); } try { station.StationName = stationRow.StationName; _context.SaveChanges(); } catch (Exception e) { return(latticeData.Adjust(x => x .Message(LatticeMessage.User("failure", "Editing", $"Save exception: {e.Message}")) )); } stationRow.StationId = station.StationId; return(latticeData.Adjust(x => x .UpdateRow(stationRow) .Message(LatticeMessage.User("success", "Editing", "Station saved")) )); }
private TableAdjustment EditOrCreate(LatticeData <TodoListEntry, TodoListEntry> latticeData) { var data = GetData(); var confirmation = latticeData.CommandConfirmation <TodoListEntryCreateEditViewModel>(); TodoListEntry entry = null; if (confirmation.Id == null) { entry = new TodoListEntry() { Date = DateTime.Now, Icon = confirmation.Icon, Id = Guid.NewGuid(), Text = confirmation.Text }; data.Add(entry); return(latticeData.Adjust(x => x .UpdateSource(entry) .Message(LatticeMessage.User("success", "Created", "New ToDo entry created")))); } entry = data.FirstOrDefault(c => c.Id == confirmation.Id); entry.Date = DateTime.Now; entry.Text = confirmation.Text; entry.Icon = confirmation.Icon; return(latticeData.Adjust(x => x .UpdateSource(entry) .Message(LatticeMessage.User("success", "Updated", "ToDo entry updated")))); }
public TableAdjustment EditRoute(LatticeData <Route, Route> latticeData, Route routeRow) { Route route = _context.Routes.FirstOrDefault(x => x.RouteId == routeRow.RouteId); if (route == null) { route = new Route() { RouteId = routeRow.RouteId }; _context.Routes.Add(route); } else { route = _context.Routes .FirstOrDefault(x => x.RouteId == routeRow.RouteId); } try { route.RouteName = routeRow.RouteName; _context.SaveChanges(); } catch (Exception e) { return(latticeData.Adjust(x => x .Message(LatticeMessage.User("failure", "Editing", $"Save exception: {e.Message}")) )); } routeRow.RouteId = route.RouteId; return(latticeData.Adjust(x => x .UpdateRow(routeRow) .Message(LatticeMessage.User("success", "Editing", "Route saved")) )); }
public TableAdjustment EditTrains(LatticeData <Train, Train> latticeData, Train trainRow) { Train train = _context.Trains .FirstOrDefault(x => x.TrainId == trainRow.TrainId); if (train == null) { train = new Train() { TrainId = trainRow.TrainId }; _context.Trains.Add(train); } try { _context.SaveChanges(); } catch (Exception e) { return(latticeData.Adjust(x => x .Message(LatticeMessage.User("failure", "Editing", $"Save exception: {e.Message}")) )); } trainRow.TrainId = train.TrainId; return(latticeData.Adjust(x => x .UpdateRow(trainRow) .Message(LatticeMessage.User("success", "Editing", "Train saved")) )); }
public TableAdjustment EditRoutePoint(LatticeData <RoutePoint, RoutePointRow> latticeData, RoutePointRow routePointRow, int routeId) { RoutePoint routePoint; if (routePointRow.RouteId == 0) { routePoint = new RoutePoint { RouteId = routeId, StationOrder = _context.RoutePoints.Where(x => x.RouteId == routeId) .Select(x => x.StationOrder) .DefaultIfEmpty(0) .Max() + 1 }; _context.RoutePoints.Add(routePoint); } else { routePoint = _context.RoutePoints .FirstOrDefault(x => x.RouteId == routePointRow.RouteId && x.StationOrder == routePointRow.StationOrder); } Station station = _context.Stations.FirstOrDefault(x => x.StationName == routePointRow.StationName); if (station == null) { return(latticeData.Adjust(x => x .Message(LatticeMessage.User("failure", "Editing", $"There is no station with name {routePointRow.StationName}")) )); } if (_context.RoutePoints.Any(x => x.RouteId == routeId && x.StationOrder != routePoint.StationOrder && x.Station.StationId == station.StationId)) { return(latticeData.Adjust(x => x .Message(LatticeMessage.User("failure", "Editing", $"The route already has station {station.StationName}")) )); } routePoint.Station = station; _context.SaveChanges(); return(latticeData.Adjust(x => x .Update(routePoint) .Message(LatticeMessage.User("success", "Editing", "Route saved")) )); }
public TableAdjustment RemoveRole(LatticeData <Employee, EmployeeRow> latticeData) { var comandModel = latticeData.CommandConfirmation <TargetRoleCommandViewModel>(); var subj = latticeData.CommandSubject(); var employee = _context.Employees.FirstOrDefault(x => x.UserId == subj.UserId); _userManager.RemoveFromRole(employee.UserId, comandModel.TargetRole); return(latticeData.Adjust(x => x .Message(LatticeMessage.User("success", "Remove", "Role was removed")) )); }
public TableAdjustment RemoveStation(LatticeData <Station, Station> latticeData) { var subj = latticeData.CommandSubject(); var station = _context.Stations.FirstOrDefault(x => x.StationId == subj.StationId); _context.Stations.Remove(station); _context.SaveChanges(); return(latticeData.Adjust(x => x .RemoveExact(subj) .Message(LatticeMessage.User("success", "Remove", "Station removed")) )); }
public TableAdjustment RemoveRoute(LatticeData <Route, RouteRow> latticeData) { var subj = latticeData.CommandSubject(); var route = _context.Routes.FirstOrDefault(x => x.RouteId == subj.RouteId); _context.Routes.Remove(route); _context.SaveChanges(); return(latticeData.Adjust(x => x .Remove(subj) .Message(LatticeMessage.User("success", "Remove", "Route removed")) )); }
public TableAdjustment RemoveTrip(LatticeData <Trip, TripRow> latticeData) { var subj = latticeData.CommandSubject(); var trip = _context.Trips.FirstOrDefault(x => x.TripId == subj.TripId); _context.Trips.Remove(trip); _context.SaveChanges(); return(latticeData.Adjust(x => x .Remove(subj) .Message(LatticeMessage.User("success", "Remove", "Trip removed")) )); }
public TableAdjustment RemoveTripPoint(LatticeData <TripPoint, TripPoint> latticeData) { var subj = latticeData.CommandSubject(); var tripPoint = _context.TripPoints .FirstOrDefault(x => x.TripId == subj.TripId && x.StationOrder == subj.StationOrder); _context.TripPoints.Remove(tripPoint); _context.SaveChanges(); return(latticeData.Adjust(x => x .RemoveExact(subj) .Message(LatticeMessage.User("success", "Remove", "RoutePoint removed")) )); }
public TableAdjustment RemoveEmployee(LatticeData <Employee, EmployeeRow> latticeData) { var subj = latticeData.CommandSubject(); var employee = _context.Employees.FirstOrDefault(x => x.UserId == subj.UserId); _userManager.Delete(employee.ApplicationUser); //_context.Employees.Remove(employee); удаляеться из за зависимости от usera // _context.SaveChanges(); return(latticeData.Adjust(x => x .Remove(subj) .Message(LatticeMessage.User("success", "Remove", "Employee removed")) )); }
public TableAdjustment EditTrip(LatticeData <Trip, TripRow> latticeData, TripRow tripRow) { Trip trip; if (tripRow.TripId == 0) { trip = new Trip(); _context.Trips.Add(trip); } else { trip = _context.Trips .FirstOrDefault(x => x.TripId == tripRow.TripId); } //на всякий случай(по идее, если сделано через форму то никогда не сработает) if (!_context.Routes.Any(x => x.RouteId == tripRow.RouteId)) { return(latticeData.Adjust(x => x .Message(LatticeMessage.User("failure", "Editing", $"There is no route with id {tripRow.RouteId}")) )); } if (!_context.Trains.Any(x => x.TrainId == tripRow.TrainId)) { return(latticeData.Adjust(x => x .Message(LatticeMessage.User("failure", "Editing", $"There is no train with id {tripRow.TrainId}")) )); } trip.RouteId = tripRow.RouteId; trip.TrainId = tripRow.TrainId; _context.SaveChanges(); var mpd = latticeData.Configuration.MapRange(latticeData.Source.Where(t => t.TripId == trip.TripId)); return(latticeData.Adjust(x => x .Update(mpd) .Message(LatticeMessage.User("success", "Editing", "Trip saved")) )); }
private TableAdjustment Complete(LatticeData <TodoListEntry, TodoListEntry> latticeData) { try { var data = GetData(); var subj = latticeData.CommandSubject(); var entry = data.FirstOrDefault(c => c.Id == subj.Id); data.Remove(entry); var msg = string.Format("'{0}' task successfulyl completed", entry.Text); return(latticeData.Adjust(x => x.RemoveExact(entry) .Message(LatticeMessage.User("success", "Completed", msg)))); } catch (Exception e) { return(latticeData.Adjust(x => x .Message(LatticeMessage.User("error", "Error", e.Message)))); } }
public TableAdjustment EditRoutePoint(LatticeData <RoutePoint, RoutePoint> latticeData, RoutePoint routePointRow) { RoutePoint routePoint = _context.RoutePoints .FirstOrDefault(x => x.RouteId == routePointRow.RouteId && x.StationOrder == routePointRow.StationOrder); if (routePoint == null) { routePoint = new RoutePoint { RouteId = routePointRow.RouteId, StationOrder = routePointRow.StationOrder }; _context.RoutePoints.Add(routePoint); } else { routePoint = _context.RoutePoints .FirstOrDefault(x => x.RouteId == routePointRow.RouteId && x.StationOrder == routePointRow.StationOrder); } try { routePoint.StationId = routePointRow.StationId; _context.SaveChanges(); } catch (Exception e) { return(latticeData.Adjust(x => x .Message(LatticeMessage.User("failure", "Editing", $"Save exception: {e.Message}")) )); } return(latticeData.Adjust(x => x .UpdateRow(routePointRow) .Message(LatticeMessage.User("success", "Editing", "RoutePoint saved")) )); }
public TableAdjustment RemoveTripPoint(LatticeData <TripPoint, TripPointForRow> latticeData) { var subj = latticeData.CommandSubject(); if (_context.TripPoints.Any(x => x.TripId == subj.TripId && x.StationOrder == subj.StationOrder + 1)) { return(latticeData.Adjust(x => x .Message(LatticeMessage.User("failure", "Remove", "Can not delete point from the middle of route")) )); } var tripPoint = _context.TripPoints .FirstOrDefault(x => x.TripId == subj.TripId && x.StationOrder == subj.StationOrder); _context.TripPoints.Remove(tripPoint); _context.SaveChanges(); return(latticeData.Adjust(x => x .Remove(subj) .Message(LatticeMessage.User("success", "Remove", "RoutePoint removed")) )); }
public TableAdjustment EditTrip(LatticeData <Trip, Trip> latticeData, Trip tripRow) { Trip trip; if (tripRow.TripId == 0) { trip = new Trip(); _context.Trips.Add(trip); } else { trip = _context.Trips.FirstOrDefault(x => x.TripId == tripRow.TripId); } if (!(_context.Routes.Any(x => x.RouteId == tripRow.RouteId))) { return(latticeData.Adjust(x => x .Message(LatticeMessage.User("failure", "Editing", $"There is no route with id {tripRow.RouteId}")) )); } if (!(_context.Trains.Any(x => x.TrainId == tripRow.TrainId))) { return(latticeData.Adjust(x => x .Message(LatticeMessage.User("failure", "Editing", $"There is no train with id {tripRow.TrainId}")) )); } trip.RouteId = trip.RouteId; trip.TrainId = tripRow.TrainId; _context.SaveChanges(); tripRow.TripId = trip.TripId; return(latticeData.Adjust(x => x .UpdateRow(tripRow) .Message(LatticeMessage.User("success", "Editing", "Trip saved")) )); }
public TableAdjustment EditRoute(LatticeData <Route, RouteRow> latticeData, RouteRow routeRow) { Route route; if (routeRow.RouteId == 0) { route = new Route(); _context.Routes.Add(route); } else { route = _context.Routes .FirstOrDefault(x => x.RouteId == routeRow.RouteId); } route.RouteName = routeRow.RouteName; _context.SaveChanges(); routeRow.RouteId = route.RouteId; return(latticeData.Adjust(x => x .Update(routeRow) .Message(LatticeMessage.User("success", "Editing", "Route saved")) )); }
public TableAdjustment EditTripPoint(LatticeData <TripPoint, TripPoint> latticeData, TripPoint tripripPointRow) { TripPoint tripPoint = _context.TripPoints .FirstOrDefault(x => x.TripId == tripripPointRow.TripId && x.StationOrder == tripripPointRow.StationOrder); ; if (tripPoint == null) { tripPoint = new TripPoint() { TripId = tripripPointRow.TripId, StationOrder = tripripPointRow.StationOrder }; _context.TripPoints.Add(tripPoint); } try { tripPoint.DepartureTime = tripripPointRow.DepartureTime; tripPoint.ArrivalTime = tripripPointRow.ArrivalTime; _context.SaveChanges(); } catch (Exception e) { return(latticeData.Adjust(x => x .Message(LatticeMessage.User("failure", "Editing", $"Save exception: {e.Message}")) )); } return(latticeData.Adjust(x => x .UpdateRow(tripripPointRow) .Message(LatticeMessage.User("success", "Editing", "TripPoint saved")) )); }
public TableAdjustment EditTripPoint(LatticeData <TripPoint, TripPointForRow> latticeData, TripPointForRow tripPointRow, int tripId) { TripPoint tripPoint; if (tripPointRow.TripId == 0) { tripPoint = new TripPoint() { TripId = tripId, StationOrder = _context.TripPoints.Where(x => x.TripId == tripId).Select(x => x.StationOrder) .DefaultIfEmpty(0).Max() + 1 }; int routeId = _context.Trips.FirstOrDefault(t => t.TripId == tripId).RouteId; if (_context.RoutePoints.Where(rp => rp.RouteId == routeId) .Any(rp => rp.StationOrder == tripPoint.StationOrder)) { _context.TripPoints.Add(tripPoint); } else { return(latticeData.Adjust(x => x .Message(LatticeMessage.User("failure", "Editing", "There are not more stationsin the route")) )); } } else { tripPoint = _context.TripPoints .FirstOrDefault(x => x.TripId == tripId && x.StationOrder == tripPointRow.StationOrder); } Delay delay = tripPoint.Delay; if (tripPointRow.DelayinMinutes.HasValue && tripPointRow.DelayinMinutes != 0) { if (delay != null) { delay.MinutesDelaySpan = tripPointRow.DelayinMinutes.Value; } else { tripPoint.Delay = new Delay() { TripPoint = tripPoint, MinutesDelaySpan = tripPointRow.DelayinMinutes.Value }; } } else { if (delay != null) { _context.Delays.Remove(delay); } } if (tripPointRow.DepartureTime.HasValue && tripPointRow.ArrivalTime.HasValue && tripPointRow.DepartureTime < tripPointRow.ArrivalTime) { return(latticeData.Adjust(x => x .Message(LatticeMessage.User("failure", "Editing", "Depatrure time can not be less then ArrivialTime")) )); } if (tripPoint.StationOrder > 1 && tripPointRow.ArrivalTime.HasValue) { TripPoint previousPoint = _context.TripPoints .FirstOrDefault(x => x.TripId == tripId && x.StationOrder == tripPoint.StationOrder - 1); if (previousPoint != null && tripPointRow.ArrivalTime < previousPoint.DepartureTime) { return(latticeData.Adjust(x => x .Message(LatticeMessage.User("failure", "Editing", "Arrivial time less then previous departure")) )); } } try { tripPoint.DepartureTime = tripPointRow.DepartureTime; tripPoint.ArrivalTime = tripPointRow.ArrivalTime; _context.SaveChanges(); } catch (Exception e) { return(latticeData.Adjust(x => x .Message(LatticeMessage.User("failure", "Editing", $"Save exception: {e.Message}")) )); } tripPointRow.TripId = tripPoint.TripId; var mpd = latticeData.Configuration.MapRange(latticeData.Source.Where(tp => tp.TripId == tripPoint.TripId && tp.StationOrder == tripPoint.StationOrder)); return(latticeData.Adjust(x => x.Update(mpd) .Message(LatticeMessage.User("success", "Editing", "TripPoint saved")) )); }