Exemple #1
0
        public bool Delete(string key, string userId)
        {
            var order = _context.Orders
                        .Include(o => o.OrderItems)
                        .ThenInclude(a => a.OrderItemOptions)
                        .FirstOrDefault(x => x.OrderId == key && x.CreatedBy == userId);

            if (order == null)
            {
                return(false);
            }

            //because of cascade probelm in sqlite, let remove dependency one by one
            foreach (var item in order.OrderItems)
            {
                _context.Remove(item);
            }

            _context.Remove(order);
            _context.SaveChanges();
            return(true);
        }
        public bool Delete(int key, string userId)
        {
            var item = _context.OrderItems
                       .Include(a => a.OrderItemOptions)
                       .FirstOrDefault(x => x.OrderItemId == key && x.CreatedBy == userId);

            if (item == null)
            {
                return(false);
            }

            _context.Remove(item);
            _context.SaveChanges();
            return(true);
        }