public async Task <IActionResult> AddBike([FromBody] Bike bikeModel) { if (ModelState.IsValid) { try { var bikeId = await bikeRepository.AddBike(bikeModel); if (bikeId > 0) { return(Ok(bikeId)); } else { return(NotFound()); } } catch (Exception) { return(BadRequest()); } } return(BadRequest()); }
public ActionResult <BikeModelDto> AddBike(BikeAddDto bikeAddDto) { var bikeModel = _mapper.Map <BikeModel>(bikeAddDto); _bikeRepo.AddBike(bikeModel); _bikeRepo.SaveChanges(); var bikeModelDto = _mapper.Map <BikeModelDto>(bikeModel); return(CreatedAtRoute(nameof(GetBikeById), new { Id = bikeModelDto.Id }, bikeModelDto)); }
public async Task <ActionResult> Edit(Bike bike) { TempData["message"] = string.Empty; string message; if (bike == null) { return(View(new BikeViewModel())); } bool succeeded; //add new bike if (bike.BikeID == 0) { succeeded = await repository.AddBike(bike); message = $"{bike.BikeID} has not been added"; //Checking the response is successful or not if (succeeded) { message = $"{bike.BikeID} has been added"; } } else { //update existing bike succeeded = await repository.UpdateBike(bike); message = $"{bike.BikeID} has not been saved"; //Checking the response is successful or not if (succeeded) { message = $"{bike.BikeID} has been saved"; } } TempData["message"] = message; if (succeeded) { return(RedirectToAction("Index")); } var model = new BikeViewModel { Bike = bike }; return(View(model)); }
public void AddBike(IBike bike) { _bikeRepository.AddBike(bike).Wait(); }