public async Task <IActionResult> Delete(int id) { try { var cont = await _container.GetById(id); if (cont == null) { return(NotFound()); } _container.Delete(cont); if (await _container.SaveChangesAsync()) { return(Ok()); } } catch (System.Exception) { return(this.StatusCode(StatusCodes.Status500InternalServerError, "Banco de dados Falhou")); } return(BadRequest()); }
public async Task <ActionResult <Container> > DeleteContainer(int id) { var container = await _repo.GetByIdAsync(id); if (container == null) { return(NotFound()); } if (container.Volume > 0) { return(BadRequest("Container should be empty")); } _repo.Delete(container); await _repo.SaveChangesAsync(); return(container); }
public int DeleteOrder(DateTime orderD, string orderNo, bool isConfirmedDeleting) { var orderToRemove = _orderRepository.Query(p => p.OrderD == orderD && p.OrderNo == orderNo).FirstOrDefault(); var containerToRemoves = _containerRepository.Query(p => p.OrderD == orderD && p.OrderNo == orderNo); var dispatchToRemoves = _dispatchRepository.Query(p => p.OrderD == orderD && p.OrderNo == orderNo); //checking Order's Dispatches Status before delete var isDeleteOder = IsDeleteOrder(containerToRemoves, dispatchToRemoves); //The order will not be deleted with Level.NotDeleted and Level.NotDeleteAndWarning but isDeletedWithoutWarning is false if (isDeleteOder == Convert.ToInt32(DeleteLevel.NotDeleted) || (isDeleteOder == Convert.ToInt32(DeleteLevel.NotDeletedAndWarning) && !isConfirmedDeleting) || (isDeleteOder == Convert.ToInt32(DeleteLevel.Deleted) && !isConfirmedDeleting)) { return(isDeleteOder); } //Process deleting Order var expenseDs = _expenseDetailRepository.Query(p => p.OrderD == orderD && p.OrderNo == orderNo); if (expenseDs != null) { foreach (var expenseD in expenseDs) { _expenseDetailRepository.Delete(expenseD); } } var surchargeDs = _surchargeDetailRepository.Query(p => p.OrderD == orderD && p.OrderNo == orderNo); if (surchargeDs != null) { foreach (var surchargeD in surchargeDs) { _surchargeDetailRepository.Delete(surchargeD); } } var allowanceDs = _allowanceDetailRepository.Query(p => p.OrderD == orderD && p.OrderNo == orderNo); if (allowanceDs != null) { foreach (var allowanceD in allowanceDs) { _allowanceDetailRepository.Delete(allowanceD); } } if (dispatchToRemoves != null) { foreach (var dispatchToRemove in dispatchToRemoves) { _dispatchRepository.Delete(dispatchToRemove); } } if (containerToRemoves != null) { foreach (var containerToRemove in containerToRemoves) { _containerRepository.Delete(containerToRemove); } } if (orderToRemove != null) { _orderRepository.Delete(orderToRemove); } SaveOrder(); return(isDeleteOder); }