public IActionResult AddTrain(CreatedWagon createdWagon) { int idOfNewElement = _wagons.AddWagon(createdWagon); if (idOfNewElement > 0) { Wagon railwayWagon = createdWagon.ToWagon(); railwayWagon.WagonId = idOfNewElement; return(Created(HttpContext.Request.Scheme + "//" + HttpContext.Request.Host + HttpContext.Request.Path + "/" + idOfNewElement, railwayWagon)); } else { return(NotFound("Addition didn't occure")); } }
public static Wagon ToWagon(this CreatedWagon wagon) { if (wagon != null) { return(new Wagon { WagonConfigId = wagon.WagonConfigId, Number = wagon.Number, NumberOfPlaces = wagon.NumberOfPlaces, TrainId = wagon.TrainId }); } else { return(null); } }
public int AddWagon(CreatedWagon createdWagon) { Wagon wagon = createdWagon.ToWagon(); return(_wagonRepository.Insert(wagon.ToEntity())); }