/// <inheritdoc /> /// <summary> /// Inserts a new Point /// </summary> /// <param name="newPointName">The name of the new point to create</param> /// <param name="ct">Cancellation token to stop the insertion of the points</param> /// <returns>Returns the Id of the created point</returns> public async Task <Guid> CreatePointAsync(string newPointName, CancellationToken ct) { var id = Guid.NewGuid(); var newPoint = _context.Points.Add(new PointEntity { Id = id, Name = newPointName }); var created = await _context.SaveChangesAsync(ct); if (created < 1) { throw new InvalidOperationException(Resources.CouldNotCreatePoint); } return(id); }
/// <inheritdoc /> /// <summary> /// Inserts a new Route /// </summary> /// <param name="newRouteToCreate">The fields of the new route to create</param> /// <param name="ct">Cancellation token to stop the insertion of the route</param> /// <returns>Returns the Id of the created route</returns> public async Task<Guid> CreateRouteAsync(RouteCreate newRouteToCreate, CancellationToken ct) { if (newRouteToCreate == null) return Guid.Empty; var id = Guid.NewGuid(); var newRoute = _context.Routes.Add(new RouteEntity() { Id = id, Name = newRouteToCreate?.RouteName, Origin = _context.Points.FirstOrDefault(point => point.Id == newRouteToCreate.Origin), Destination = _context.Points.FirstOrDefault(point => point.Id == newRouteToCreate.Destination), Cost = newRouteToCreate.Cost, Time = newRouteToCreate.Time }); var created = await _context.SaveChangesAsync(ct); if (created < 1) throw new InvalidOperationException(Resources.CouldNotCreateRoute); return id; }