public ActionResult <GetTruckResult> CreateTruck([FromBody] CreateTruckInput input) { try { var result = this.TruckService.Create(input); return(!(result is null) ? this.Ok(result) : this.BadRequest() as ActionResult); } catch (Exception ex) { this.Logger.LogError(ex, $"Error creating Truck"); return(this.BadRequest()); } }
public GetTruckResult Create(CreateTruckInput input) { if (input is null) { throw new ArgumentNullException(nameof(input)); } this.CreateValidator.ValidateAndThrow(input); var newData = this.ModelMapper.Map <Truck>(input); var created = this.Repository.AddTruck(newData); this.Repository.Save(); created.Reload(); return(this.ModelMapper.Map <GetTruckResult>(created.Entity)); }