public async Task <IActionResult> GetProduct(int id) { var product = await _repo.GetProduct(id); var productToReturn = _mapper.Map <ProductForDetailDto>(product); return(Ok(productToReturn)); }
public async Task <IActionResult> Get(string code) { var productFromRepo = await _repository.GetProduct(code); if (productFromRepo == null) { return(NotFound()); } var productToReturn = _mapper.Map <ProductToReturnDto>(productFromRepo); return(Ok(productToReturn)); }
public ActionResult UpdateProduct(Guid id, ProductUpdateDTO product) { var productFromRepo = _repository.GetProduct(id); _mapper.Map(product, productFromRepo); _repository.save(); return(Ok()); }
public async Task <IActionResult> AddPhotoForProduct(int idProduct, [FromForm] PhotoForCreationDto photoForCreationDto) { var product = await _repo.GetProduct(idProduct); 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), Transformation = new Transformation() .Width(500).Height(500).Crop("fill").Gravity("face") }; uploadResult = _cloudinary.Upload(uploadParams); } } photoForCreationDto.Url = uploadResult.Uri.ToString(); photoForCreationDto.PublicId = uploadResult.PublicId; var photo = _mapper.Map <Photo>(photoForCreationDto); if (!product.Photos.Any(u => u.IsMain)) { photo.IsMain = true; } product.Photos.Add(photo); if (await _repo.SaveAll()) { var photoToReturn = _mapper.Map <PhotoForReturnDto>(photo); return(CreatedAtRoute("GetPhoto", new { id = photo.Id }, photoToReturn)); } return(BadRequest("Could not add the photo")); }
public ActionResult <Product> GetProduct(Guid id) { return(_repository.GetProduct(id)); }