Exemplo n.º 1
0
        public async Task DeletePicAsync(int id)
        {
            CategoryDbModel categoryDb = m_db.Categories.FirstOrDefault(x => x.Id == id);

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

            categoryDb.Pic = null;
            await m_db.SaveChangesAsync();
        }
        public async Task DeletePicAsync(int productId, int fileId)
        {
            ProductDbModel productDb = m_db.Products.Include(x => x.Pics).FirstOrDefault(x => x.Id == productId);

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

            var deletingProductPic = productDb.Pics.FirstOrDefault(x => x.Id == fileId);

            m_repositoryService.DeleteFileAsync($@"{productRepoPath}/{productId}/{deletingProductPic.FileName}");

            m_db.Entry(deletingProductPic).State = EntityState.Deleted;

            await m_db.SaveChangesAsync();
        }