/// <summary>Exclui uma determinada mensagem</sumary> public ObjResult DeleteMessage(int msg_id) { connection = db.GetCon(); connection.Open(); NpgsqlTransaction transaction = connection.BeginTransaction(); MessageDao dao = new MessageDao(connection, transaction); ObjResult result = new ObjResult(); try { msg_id = dao.Delete(msg_id); result.SetData(msg_id); result.Success(); transaction.Commit(); } catch (Exception e) { transaction.Rollback(); throw new Exception(e.ToString()); } finally { connection.Close(); } return(result); }
/// <summary>Exclui uma determinada requisição</sumary> public ObjResult Delete(int request_id) { connection = db.GetCon(); connection.Open(); ObjResult result = new ObjResult(); List <RequestItem> items = new List <RequestItem>(); List <Message> messages = new List <Message>(); // Excluir a requisição NpgsqlTransaction transaction = connection.BeginTransaction(); RequestDao dao = new RequestDao(connection, transaction); RequestItemDao itemDao = new RequestItemDao(connection, transaction); MessageDao messageDao = new MessageDao(connection, transaction); try { // Verifica se a requisição possui itens items = itemDao.GetItemsByRequest(request_id); if (items.Count > 0) { // Exclui todos os itens que pertencem à requisição foreach (RequestItem item in items) { itemDao.Delete(item.itm_id); } } // Verifica se a requisição possui mensagens messages = messageDao.GetMessagesBySourceKey(request_id); if (messages.Count > 0) { // Exclui todas as mensagens associadas à requisição foreach (Message msg in messages) { messageDao.Delete(msg.msg_id); } } request_id = dao.Delete(request_id); result.SetData(request_id); result.Success(); transaction.Commit(); } catch (Exception e) { transaction.Rollback(); throw new Exception(e.ToString()); } finally { connection.Close(); } return(result); }
public ResponseDto <string> Delete(RequestDto <int> request) { try { _dao.Delete(request.Obj); return(new ResponseDto <string>() { Message = "", Status = Status.Ok }); } catch (Exception ex) { return(new ResponseDto <string>() { Message = String.Format("Erro ao deletar a mensagem. Msg: {0}", ex.Message), Status = Status.Error }); } }
public bool Delete(int id) => _messages.Delete(id);