コード例 #1
0
        public async Task Delete(Guid id)
        {
            if (id == Guid.Empty)
            {
                throw new InvalidArgumentException($"Id is not a valid {nameof(Guid)}!");
            }

            var item = await _readOnly.GetQueryable <Product>(x => x.Id == id,
                                                              isDeleted : null)
                       .Select(x => new Product
            {
                Id        = x.Id,
                IsDeleted = x.IsDeleted
            }).FirstOrDefaultAsync();

            if (item == null)
            {
                throw new NotFoundException($"Can't find a {typeof(Product).Name} with ID = {id}!");
            }

            if (item.IsDeleted == true)
            {
                throw new LogicalException($"{typeof(Product).Name} with ID = {id} was removed!");
            }

            await _writeOnly.DeleteByIdAsync <Product>(id);
        }