Exemplo n.º 1
0
        public async Task <Product> ItemLoadChild(Product item)
        {
            _db.Attach <Product>(item);
            await _db.Entry <Product>(item).Collection <Image>(p => p.Images).LoadAsync();

            return(item);
        }
        public async Task <RepositoryResponseDto> DeleteImage(Image item)
        {
            RepositoryResponseDto flag = new RepositoryResponseDto {
                Flag = false, Message = null, Item = null
            };
            int i = 0;

            try{
                // Image item= await    _db.Images.Where(p=>p.Id==id).FirstOrDefaultAsync();
                _db.Attach <Image>(item);
                _db.Images.Remove(item);
                i = await _db.SaveChangesAsync();
            }
            catch (Exception ex)
            {
                Console.WriteLine("---UploadImageRepository----Ошибка БД Images delete not(false)!");
                Console.WriteLine(ex.Message);
                flag.Message = "БД Images delete not(false)!";
                flag.Flag    = false;
            }
            if (i != 0)
            {
                flag.Message = "БД Images delete ok!";
                flag.Flag    = true;
                flag.Item    = null;
                return(flag);
            }
            else
            {
                flag.Message = "БД Images delete not(false)!";
                flag.Flag    = false;
                flag.Item    = null;
                return(flag);
            }

            //  throw new Exception("not implimetn exeption 14.11.20");
            // return await _db.TypeProduct.ToListAsync();
        }