public IActionResult Post([FromBody] VehicleType model)
 {
     try
     {
         if (!ModelState.IsValid)
         {
             return(InvalidModelStateResult());
         }
         if (!validateEntity(model))
         {
             return(InvalidModelStateResult());
         }
         return(Accepted(repository.Create(model)));
     }
     catch (Exception ex)
     {
         logger.LogError(ex.GetExceptionMessages());
         return(StatusCode(StatusCodes.Status500InternalServerError, Constants.ErrorMessages.CreateError));
     }
 }
 public IActionResult Create(VehicleCreateModel model)
 {
     foreach (VehicleType vehicleType in model.VehicleTypes)
     {
         if (vehicleTypeRepository.Exists(vehicleType))
         {
             ModelState.AddModelError(string.Empty, "VehicleType already exists");
         }
         if (ModelState.IsValid)
         {
             vehicleType.Id = vehicleTypeRepository.Create(vehicleType);
         }
     }
     foreach (Vehicle vehicle in model.Vehicles)
     {
         if (vehicleRepository.Exists(vehicle))
         {
             ModelState.AddModelError(string.Empty, "Vehicle already exists");
         }
         if (ModelState.IsValid)
         {
             VehicleType previouslyStoredType = vehicleTypeRepository.GetByTitle(vehicle.VehicleType.Title);
             if (previouslyStoredType != null)
             {
                 vehicle.VehicleTypeId = previouslyStoredType.Id;
                 vehicleRepository.Create(vehicle);
             }
         }
     }
     if (ModelState.IsValid)
     {
         return(RedirectToAction("Index"));
     }
     ViewData["CompanyId"]     = new SelectList(companyRepository.GetAll(), "Id", "Title");
     ViewData["VehicleTypeId"] = new SelectList(companyRepository.GetAll(), "Id", "Title");
     return(View(model));
 }