Example #1
0
        public void Delete(int Id)
        {
            try
            {
                var entity = _entity.Where(c => c.Id == Id).FirstOrDefault();

                if (entity != null)
                {
                    _bikeStoresContext.Remove(entity);
                }
            }
            catch (Exception)
            {
                throw;
            }
        }
Example #2
0
            public async Task <Unit> Handle(Command request, CancellationToken cancellationToken)
            {
                var customer = await bikeStoresContext.Customers.FindAsync(request.Id);

                if (customer == null)
                {
                    throw new Exception("no customer found to delete");
                }

                bikeStoresContext.Remove(customer);
                var sucess = await bikeStoresContext.SaveChangesAsync() > 0;

                if (sucess)
                {
                    return(Unit.Value);
                }

                throw new Exception("unable to save changes");
            }