Exemplo n.º 1
0
        public OperationResult <bool> DeleteCustomer(string id)
        {
            var result = new OperationResult <bool>();

            try
            {
                var customer = _customerRepo.Get(id);
                if (customer != null)
                {
                    _customerRepo.Delete(customer);
                    foreach (var address in customer.Addresses)
                    {
                        _addrRepo.Delete(address);
                    }
                    var saveResult = _context.SaveChanges();
                    if (saveResult > 0)
                    {
                        result.Data   = true;
                        result.Status = eOperationStatus.Success;
                    }
                    else
                    {
                        result.Data   = false;
                        result.Status = eOperationStatus.GeneralError;
                    }
                }
                else
                {
                    result.Data   = false;
                    result.Status = eOperationStatus.NotFound;
                }
            }
            catch (Exception ex)
            {
                result.Data             = false;
                result.Status           = eOperationStatus.GeneralError;
                result.ExceptionMessage = ex.Message;
            }

            return(result);
        }
        public async Task <IActionResult> Delete(int id)
        {
            Address OldAddress = await repo.GetAddressById(id);

            if (OldAddress == null)
            {
                return(NotFound());
            }

            //delete the item in the db
            await repo.Delete(id);

            return(NoContent());
        }