コード例 #1
0
 public async Task <ApiResponse <Guid> > Post([FromBody] FuelingEditDto newFueling) =>
 await ValidateFuelingDto(newFueling)
 .Map(FuelingMapper.MapToNewFueling)
 .BindAsync(fueling => Storage.Create(fueling))
 .MapAsync(fueling => fueling.Id)
 .DoWhenErrorAsync(e => Logger.Warn(e.Message, e.Exception))
 .ToResponseAsync();
コード例 #2
0
 public static Fueling MapToFueling(Guid id, FuelingEditDto dto) =>
 new Fueling
 {
     Id         = id,
     CarId      = Guid.Parse(dto.CarId),
     When       = DateTime.Parse(dto.When),
     FuelAmount = dto.FuelAmount,
     FuelPrice  = dto.FuelPrice
 };
コード例 #3
0
 public async Task <ApiResponse <Unit> > Put(string fuelingId, [FromBody] FuelingEditDto updatedFueling) =>
 await GuidParser.ParseGuid(fuelingId)
コード例 #4
0
 public static Result <FuelingEditDto> ValidateFuelingDto(FuelingEditDto fueling) =>
 fueling
 .ToResult(() => Errors.Error("Fueling cannot be null"))
 .Bind(f => f.FuelAmount <= 0 ? Error <FuelingEditDto>(Errors.Error("Fuel amount must be > 0")) : Ok(f))
 .Bind(f => f.FuelPrice <= 0 ? Error <FuelingEditDto>(Errors.Error("Fuel price must be > 0")) : Ok(f));