コード例 #1
0
        public async Task <IActionResult> AddPhotoForNutritionFact(int NutritionFactId, [FromForm] PhotosNForCreationDto pdto)
        {
            var nutritionfromrepo = await _repo.GetNutritionFact(NutritionFactId);

            var file         = pdto.File;
            var uploadResult = new ImageUploadResult();

            if (file.Length > 0)
            {
                using (var stream = file.OpenReadStream())
                {
                    var uploadparam = new ImageUploadParams()
                    {
                        File           = new FileDescription(file.Name, stream),
                        Transformation = new Transformation().Width(500).Height(500).Crop("fill")
                    };
                    uploadResult = _cloudinary.Upload(uploadparam);
                }
            }
            pdto.Url       = uploadResult.Uri.ToString();
            pdto.PublicNId = uploadResult.PublicId;
            var photo = _mapper.Map <PhotoN>(pdto);

            if (!nutritionfromrepo.PhotosE.Any(u => u.IsMain))
            {
                photo.IsMain = true;
            }
            nutritionfromrepo.PhotosE.Add(photo);
            if (await _repo.SaveAllN())
            {
                var photoToReturn = _mapper.Map <PhotosNForReturnDto>(photo);
                return(CreatedAtRoute("GetPhotoN", new { id = photo.Id }, photoToReturn));
            }
            return(BadRequest("Could not Add the photo"));
        }
コード例 #2
0
        public async Task <IActionResult> GetNutritionFact(int id)
        {
            var nutritionFact = await _repo.GetNutritionFact(id);

            var nutritionFactForReturn = _mapper.Map <NutritionFactForDetailedDto>(nutritionFact);

            return(Ok(nutritionFactForReturn));
        }