예제 #1
0
        public async Task <CategoryDto> CreateAsync(CategoryCreateDto categoryCreateDto)
        {
            var fileName = await ThumbnailManager.SaveAsync(categoryCreateDto.ThumbnailBase64);

            var categoryEntity = ObjectMapper.Map <CategoryCreateDto, CategoryEntity>(categoryCreateDto);

            categoryEntity.CategoryThumbnail = fileName;

            await Repository.InsertAsync(categoryEntity, autoSave : true);

            return(ObjectMapper.Map <CategoryEntity, CategoryDto>(categoryEntity));
        }
예제 #2
0
        public async Task <CategoryDto> UpdateAsync(int id, CategoryUpdateDto categoryUpdateDto)
        {
            var categoryE = await Repository.GetAsync(id) ?? throw new EntityNotFoundException();

            if (!string.IsNullOrWhiteSpace(categoryUpdateDto.ThumbnailBase64))
            {
                var categoryThumbnail = await ThumbnailManager.SaveAsync(categoryUpdateDto.ThumbnailBase64);

                await ThumbnailManager.DeleteAsync(categoryE.CategoryThumbnail);

                categoryE.CategoryThumbnail = categoryThumbnail;
            }

            ObjectMapper.Map(categoryUpdateDto, categoryE);
            await Repository.UpdateAsync(categoryE);

            return(ObjectMapper.Map <CategoryEntity, CategoryDto>(categoryE));
        }