Пример #1
0
        public async Task <bool> DeleteBrand(int?id)
        {
            try
            {
                var brandId = await _context.Brand.FindAsync(id);

                _context.Remove(brandId);
                await _context.SaveChangesAsync();

                return(true);
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                return(false);
            }
        }
Пример #2
0
        public async Task <bool> DeleteStock(int?productId, int?storeId)
        {
            try
            {
                var stockId = await _context.Stock.FirstOrDefaultAsync(x => x.ProductId == productId && x.StoreId == storeId);

                _context.Remove(stockId);
                await _context.SaveChangesAsync();

                return(true);
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                return(false);
            }
        }
Пример #3
0
        public async Task <bool> DeleteCategory(int?id)
        {
            try
            {
                var categoryId = await _context.Category.FindAsync(id);

                _context.Remove(categoryId);
                await _context.SaveChangesAsync();

                return(true);
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                return(false);
            }
        }
Пример #4
0
//        public  async Task<EditProductImageViewModel> GetIdProductImage(int? Id)
//        {
//            var findId = await _context.Product.FirstOrDefaultAsync(x => x.Id == Id);
//            var getEditProductImageViewModel = new EditProductImageViewModel(findId);
//            return getEditProductImageViewModel;
//        }
//
//        public async Task<bool> EditProductImage(EditProductImageViewModel editProductImage)
//        {
//            try
//            {
//                var product = await _context.Product.FirstOrDefaultAsync(x => x.Id == editProductImage.Id);
//                var path = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot/images",   editProductImage.Picture.FileName);
//                using (var stream = new FileStream(path, FileMode.Create))
//                {
//                    await editProductImage.Picture.CopyToAsync(stream);
//                }
//                product.Picture = editProductImage.Picture.FileName;
//                _context.Product.Update(product);
//                await _context.SaveChangesAsync();
//                return true;
//            }
//            catch (Exception e)
//            {
//                Console.WriteLine(e);
//                return false;
//            }
//
//        }

        public async Task <bool> DeleteProduct(int?id)
        {
            try
            {
                var productId = await _context.Product.FindAsync(id);

                _context.Remove(productId);
                await _context.SaveChangesAsync();

                return(true);
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                return(false);
            }
        }