public async Task <ActionResult <AirPlaneModel> > CreateAirPlane([FromBody] AirPlaneAddModel airPlane) { if (airPlane == null) { return(await Task.FromResult <ActionResult>(this.BadRequest(new ErrorModel(1, "AirPlane", "The AirPlane can not be null!").ToList()))); } if (airPlane.NumberOfPassengers > 300) { return(await Task.FromResult <ActionResult>(this.UnprocessableEntity("Air Plane number of passengers is invalid!"))); } if (AirPlaneRepository.AirPlanes.Count() > 30) { return(await Task.FromResult <ActionResult>(this.UnprocessableEntity("It is not possible to add more Air Planes, please delete the available Air Planes!"))); } if (!AirPlaneRepository.AirPlanes.Any(x => x.Model.Id == airPlane.Model.Id)) { return(await Task.FromResult <ActionResult>(this.UnprocessableEntity("There is no such model airplane registered in the system!"))); } var result = this.InsertAirPlane(airPlane); if (result == null) { return(await Task.FromResult <ActionResult>(this.UnprocessableEntity("This AirPlane has already been registered!"))); } else { return(await Task.FromResult <ActionResult>(this.Created(result.Id.ToString(), result))); } }
public async Task <ActionResult <AirPlaneModel> > CreateAirPlane([FromBody] AirPlaneAddModel airPlane) { if (airPlane == null) { return(await Task.FromResult <ActionResult>(this.BadRequest(new ErrorModel(1, "AirPlane", "The AirPlane can not be null!").ToList()))); } var entity = new AirPlaneDDD.Domain.Entities.AirPlane() { Code = airPlane.Code, NumberOfPassengers = airPlane.NumberOfPassengers, ModelId = airPlane.Model.Id }; var result = this._IAppAirPlane.AddEntity(entity); if (result.Errors.Count > 0) { return(await Task.FromResult <ActionResult>(this.UnprocessableEntity(result.Errors.First()))); } else { return(await Task.FromResult <ActionResult>(this.Created(result.Response.Id.ToString(), result.Response))); } }
private AirPlaneModel InsertAirPlane(AirPlaneAddModel airPlane) { if (AirPlaneRepository.AirPlanes.Any(x => x.Code.Equals(airPlane.Code, StringComparison.OrdinalIgnoreCase))) { return(null); } var entity = new AirPlaneModel(airPlane); AirPlaneRepository.AirPlanes.Add(entity); return(entity); }