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());
        }
Example #2
0
        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));
        }
Example #3
0
        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));
        }
Example #4
0
 public void AddBike(IBike bike)
 {
     _bikeRepository.AddBike(bike).Wait();
 }