public override async Task <Race> updateRace(Race request, ServerCallContext context) { Server.Data.Race race; if (request.Id > 0) { race = await dbContext.Races.FindAsync(request.Id); if (race == null) { throw new ArgumentException($"Race not found by Id: '{request.Id}"); } race.Name = request.Name; race.Date = request.Date.ToDateTime(); } else { race = new Data.Race(request.Name, request.Date.ToDateTime()); dbContext.Races.Add(race); } race.Description = request.Description; await dbContext.SaveChangesAsync(); return(ToProtoRace(race)); }
public async Task <Guid> Create(Models.Race rac) { try { var context = CreateContext(); var created = new Data.Race { Id = rac.Id, UniversId = rac.UniversId, NomRace = rac.NomRace, }; var enr = await context ._Race .AddAsync(created); await context.SaveChangesAsync(); return(enr.Entity.Id); } catch (DbUpdateException e) { Console.WriteLine(e.Message); return(rac.Id); } }
private static Race ToProtoRace(Data.Race r) { return(new Race { Id = r.Id, Name = r.Name, Description = r.Description, Date = Timestamp.FromDateTime(DateTime.SpecifyKind(r.Date, DateTimeKind.Utc)) }); }