コード例 #1
0
        public async Task <FoodMarkerPhoto> PostPhotoById(FoodMarkerImageData foodMarkerImageData,
                                                          string contentType, Stream stream)
        {
            var postImageMetaDto = _mapper.Map <FoodMarkerImageDataDTO>(foodMarkerImageData);

            foodMarkerImageData.Id = postImageMetaDto.Id = _repoImageMeta.Post(postImageMetaDto);

            await _repoImageFile.PostFile(postImageMetaDto, contentType, stream);

            return(new FoodMarkerPhoto
            {
                ImageUrl = _repoImageFile.GetFileUrl(postImageMetaDto),
                ImageRank = (foodMarkerImageData.ImageRank.HasValue ?
                             foodMarkerImageData.ImageRank.Value : 2)
            });
        }
コード例 #2
0
        public async Task <IActionResult> CreateFoodMarker(FoodMarkerClient reqObj)
        {
            if (reqObj == null)
            {
                BadRequest();
            }

            JSONRetObj <int?> retObj = new JSONRetObj <int?>();

            try
            {
                retObj.IsSuccess = true;
                FoodMarker    foodMarker    = Mapper.Map <FoodMarker>(reqObj);
                FoodMarkerDTO foodMarkerDto = Mapper.Map <FoodMarkerDTO>(foodMarker);
                int           foodMarkerId  = _repoFoodMarker.Post(foodMarkerDto);

                foreach (var file in Request.Form.Files)
                {
                    FoodMarkerImageData postImageMeta = new FoodMarkerImageData(foodMarkerId, file.FileName);

                    var postImageMetaDto = Mapper.Map <FoodMarkerImageDataDTO>(postImageMeta);

                    postImageMeta.Id = postImageMetaDto.Id = _repoImageMeta.Post(postImageMetaDto);

                    Stream stream = file.OpenReadStream();
                    await _repoImageFile.PostFile(postImageMetaDto, file.ContentType, stream);
                }

                retObj.ResponseObj = foodMarkerId;
            }
            catch (Exception ex)
            {
                retObj.IsSuccess = false;
                retObj.Message   = ex.Message;
            }

            ViewData["RetObj"] = retObj;

            return(View("_Success"));
        }