コード例 #1
0
        public async Task <Response <ResourceImageDTO> > CreateImageResource(Guid userId, FileGroup @group, ImageCreateDTO dto)
        {
            var resource = await CreateImageResource(userId, group.ToString().ToLower(), dto);

            var viewModel = new ResourceImageViewModel(resource);
            var result    = _mapper.Map <ResourceImageViewModel, ResourceImageDTO>(viewModel);

            return(new Response <ResourceImageDTO>
            {
                Data = result
            });
        }
コード例 #2
0
        public async Task <Response <ResourceImageViewModel> > GetImageViewModelByFileName(string filename)
        {
            var resourceResponse = await GetModelByFileName(filename);

            if (!resourceResponse.IsSuccess)
            {
                return(ErrorResponse.MapResponse <ResourceImageViewModel, ResourceModel>(resourceResponse));
            }
            var viewModel = new ResourceImageViewModel(resourceResponse.Data);

            return(new Response <ResourceImageViewModel>
            {
                Data = viewModel
            });
        }
コード例 #3
0
        public ResourceMapperProfile()
        {
            CreateMap <ByteImageCreateDTO, ImageCreateDTO>()
            .ForMember(
                item => item.ContentType,
                map => map.MapFrom(src => src.ContentType))
            .ForMember(
                item => item.Stream,
                map => map.MapFrom(src => new MemoryStream(src.Bytes)));

            CreateMap <FormImageCreateDTO, ImageCreateDTO>()
            .ForMember(
                item => item.ContentType,
                map => map.MapFrom(src => src.File.ContentType))
            .ForMember(
                item => item.Stream,
                opt => opt.MapFrom((from, to) =>
            {
                var mapped = new MemoryStream();
                from.File.CopyTo(mapped);
                return(mapped);
            }));


            CreateMap <ResourceImageViewModel, ResourceImageDTO>();
            CreateMap <ResourceViewModel, ResourceDTO>();

            CreateMap <ResourceModel, ResourceImageViewModel>().ConvertUsing((from, to) =>
            {
                if (from == null)
                {
                    return(null);
                }
                var mapped = new ResourceImageViewModel(from);
                return(mapped);
            });
            CreateMap <ResourceModel, ResourceViewModel>().ConvertUsing((from, to) =>
            {
                if (from == null)
                {
                    return(null);
                }
                var mapped = new ResourceViewModel(from);
                return(mapped);
            });

            //TODO: Think about how to map correctly
            CreateMap <ResourceModel, ResourceImageDTO>().ConvertUsing((from, to) =>
            {
                if (from == null)
                {
                    return(null);
                }
                var viewModel = new ResourceImageViewModel(from);
                return(new ResourceImageDTO
                {
                    FormatUrls = viewModel.FormatUrls,
                    OriginalUrl = viewModel.OriginalUrl,
                    ResourceId = viewModel.ResourceId
                });
            });

            //TODO: Think about how to map correctly
            CreateMap <ResourceModel, ResourceDTO>().ConvertUsing((from, to) =>
            {
                if (from == null)
                {
                    return(null);
                }
                var viewModel = new ResourceViewModel(from);
                return(new ResourceDTO
                {
                    OriginalUrl = viewModel.OriginalUrl,
                    ResourceId = viewModel.ResourceId
                });
            });
        }