public CarModel_Model GetOneCarModel(int id) { CarModel_Model carModel = DB.CarModels.Where(cm => cm.CModelId == id).Select(cm => new CarModel_Model(cm)).SingleOrDefault(); carModel.CModelCat = getOneCategory(carModel.CModelCatID); return(carModel); }
public CarModel_Model AddCarModel(CarModel_Model carModel_) { CarModel carModel = carModel_.ConvertToCar(); DB.CarModels.Add(carModel); DB.SaveChanges(); carModel_.CModelID = carModel.CModelId; return(carModel_); }
public IActionResult AddCarModel(CarModel_Model carModel) { try { if (!ModelState.IsValid) { return(BadRequest(ErrorHelper.ExtractErrors(ModelState))); } CarModel_Model addedCarModel = CarLogic.AddCarModel(carModel); return(Created("api/CarModels" + addedCarModel.CModelID, addedCarModel)); } catch (Exception ex) { return(StatusCode(StatusCodes.Status500InternalServerError, ErrorHelper.GetExceptionMessage(ex))); } }
public IActionResult GetOneCarsModels(int id) { try { CarModel_Model carModel = CarLogic.GetOneCarModel(id); if (carModel == null) { return(NotFound($"id {id} not found")); } return(Ok(carModel)); } catch (Exception ex) { return(StatusCode(StatusCodes.Status500InternalServerError, ErrorHelper.GetExceptionMessage(ex))); } }
public IActionResult UpateCarModel([FromRoute] int id, [FromBody] CarModel_Model carModel) { try { carModel.CModelID = id; CarModel_Model updatedCarModel = CarLogic.UpdateCarModel(carModel); if (updatedCarModel == null) { return(NotFound($"id {id} not found")); } return(Ok(updatedCarModel)); } catch (Exception ex) { return(StatusCode(StatusCodes.Status500InternalServerError, ErrorHelper.GetExceptionMessage(ex))); } }
public CarModel_Model UpdateCarModel(CarModel_Model carModel_) { CarModel carModel = DB.CarModels.SingleOrDefault(carModel => carModel.CModelId == carModel_.CModelID); if (carModel == null) { return(null); } carModel.CModelId = carModel_.CModelID; carModel.CModelManufacturer = carModel_.CModelManufacturer; carModel.CModelName = carModel_.CModelName; carModel.CModelCatId = carModel_.CModelCatID; carModel.PriceDay = carModel_.PriceDay; carModel.PriceLateDay = carModel_.PriceLateDay; DB.SaveChanges(); return(carModel_); }