Example #1
0
        public async Task <IActionResult> GetBike(int id)
        {
            var bike = await _bikeRepo.GetBike(id);

            var bikeToReturn = _mapper.Map <BikeForDetailedDto>(bike);

            return(Ok(bikeToReturn));
        }
        public async Task <IActionResult> Edit(Guid?id)
        {
            var bike = await _bikeRepo.GetBike(id);

            if (bike == null)
            {
                return(NotFound());
            }

            return(View(bike));
        }
Example #3
0
        public async Task <ActionResult> Edit(int?id)
        {
            var model = new BikeViewModel();

            if (id == null)
            {
                model.Bike = new Bike();
                return(View(model));
            }

            model.Bike = await repository.GetBike(id);

            //model.Bikes
            return(View(model));
        }
Example #4
0
        public async Task <IActionResult> AddPhotoForBike(int bikeId, [FromForm] PhotoForCreationDto photoForCreationDto)
        {
            var bikeFromRepo = await _bikeRepo.GetBike(bikeId);

            var file = photoForCreationDto.File;

            var uploadResult = new ImageUploadResult();

            if (file.Length > 0)
            {
                using (var stream = file.OpenReadStream())
                {
                    var uploadParams = new ImageUploadParams()
                    {
                        File   = new FileDescription(file.Name, stream),
                        Folder = "AperoApp"
                    };

                    uploadResult = _cloudinary.Upload(uploadParams);
                }
            }

            photoForCreationDto.Url      = uploadResult.Uri.ToString();
            photoForCreationDto.PublicId = uploadResult.PublicId;

            var photo = _mapper.Map <Photo>(photoForCreationDto);

            if (!bikeFromRepo.Photos.Any(u => u.IsMain))
            {
                photo.IsMain = true;
            }

            bikeFromRepo.Photos.Add(photo);

            if (await _bikeRepo.SaveAll())
            {
                var photoToReturn = _mapper.Map <PhotoForReturnDto>(photo);
                return(CreatedAtRoute("GetPhoto", new { bikeId = bikeId, id = photo.Id }, photoToReturn));
            }

            return(BadRequest("Could not add the photo"));
        }
Example #5
0
        public async Task <IActionResult> GetBike(int?bikeId)
        {
            if (bikeId == null)
            {
                return(BadRequest());
            }
            try
            {
                var bike = await _BikeRepository.GetBike(bikeId);

                if (bike == null)
                {
                    return(NotFound());
                }
                return(Ok(bike));
            }
            catch (Exception)
            {
                return(BadRequest());
            }
        }
Example #6
0
 public IBike GetBike(long id)
 {
     return(_bikeRepository.GetBike(id).Result);
 }