public async Task UploadPicAsync(int productId, IFormFile file)
        {
            ProductDbModel productDb = m_db.Products.FirstOrDefault(x => x.Id == productId);

            if (productDb is null)
            {
                throw new NotFoundException();
            }

            SavedFileInfo picInfo = await m_repositoryService.SaveFileAsync(file, $@"{productRepoPath}/{productId}", "galery", "jpeg");

            productDb.Pics.Add(m_mapper.Map <PictureInfoDbModel>(picInfo));

            await m_db.SaveChangesAsync();
        }
Esempio n. 2
0
        public async Task UploadPicAsync(int id, IFormFile file)
        {
            CategoryDbModel categoryDb = m_db.Categories.FirstOrDefault(x => x.Id == id);

            if (categoryDb is null)
            {
                throw new NotFoundException();
            }
            if (categoryDb.Pic is not null)
            {
                m_repositoryService.DeleteFileAsync(@$ "{categoryRepoPath}/{id}/{categoryDb.Pic.FileName}");
            }

            SavedFileInfo picInfo = await m_repositoryService.SaveFileAsync(file, @$ "{categoryRepoPath}/{id}", "main", "jpeg");

            categoryDb.Pic = m_mapper.Map <PictureInfoDbModel>(picInfo);

            await m_db.SaveChangesAsync();
        }