Exemplo n.º 1
0
        public static List <HistoricDTO> ListAll(string id, int init, int end)
        {
            string query = "select cd_linha_tempo as 'Id', ds_acontecimento as 'Acontecimento', " +
                           $"dt_acontecimento as 'Data', cd_usuario as 'UserId' from tb_acontecimento where cd_usuario = '{id}' " +
                           $"order by  dt_acontecimento desc OFFSET {init} ROWS FETCH NEXT {end} ROWS ONLY";

            Commands bd = new Commands();

            List <HistoricDTO> Historic       = new List <HistoricDTO>();
            string             selectProducts = query;

            SqlDataReader datareader = bd.ExecuteCommandReader(selectProducts);

            while (datareader.Read())
            {
                var this_user = new HistoricDTO
                {
                    Id        = datareader["Id"].ToString(),
                    Data      = (DateTime)datareader["Data"],
                    Descricao = datareader["Acontecimento"].ToString(),
                    UserId    = datareader["UserId"].ToString()
                };

                Historic.Add(this_user);
            }
            datareader.Close();

            return(Historic);
        }
Exemplo n.º 2
0
        public static bool RegisterHistoric(HistoricDTO hist)
        {
            try
            {
                string query = "INSERT INTO tb_acontecimento(ds_acontecimento, dt_acontecimento, cd_usuario) VALUES " +
                               $"('{hist.Descricao}','{DateTime.Now.Date}','{hist.UserId}')";

                new Commands().ExecuteCommand(query);

                return(true);
            }
            catch
            {
                return(false);
            }
        }
Exemplo n.º 3
0
        public JsonResult CreateTrade(TradeDTO trade)
        {
            var coin        = TradeCoinBLL.ListAll();
            var type        = OperationBLL.ListAll();
            var cookie_info = CookiesControll.UserAuthenticationInfo().Name;

            trade.Tipo   = type.Where(t => t.Id == trade.Tipo).FirstOrDefault().Tipo;
            trade.UserId = cookie_info;

            if (!string.IsNullOrEmpty(trade.MoedaCompra) && !string.IsNullOrWhiteSpace(trade.MoedaCompra))
            {
                trade.MoedaCompra = coin.Where(c => c.Id == trade.MoedaCompra).FirstOrDefault().Sigla;
            }

            if (!string.IsNullOrEmpty(trade.MoedaVenda) && !string.IsNullOrWhiteSpace(trade.MoedaVenda))
            {
                trade.MoedaVenda = coin.Where(c => c.Id == trade.MoedaVenda).FirstOrDefault().Sigla;
            }

            if (!string.IsNullOrEmpty(trade.MoedaTaxa) && !string.IsNullOrWhiteSpace(trade.MoedaTaxa))
            {
                trade.MoedaTaxa = coin.Where(c => c.Id == trade.MoedaTaxa).FirstOrDefault().Sigla;
            }

            bool inserts_ok = false;

            if (TradeBLL.RegisterUser(trade))
            {
                inserts_ok = true;

                HistoricDTO hist = new HistoricDTO
                {
                    Data      = DateTime.Now.Date,
                    UserId    = cookie_info,
                    Descricao = $"Adicionado uma nova {trade.Tipo}"
                };

                inserts_ok = HistoricBLL.RegisterHistoric(hist);
            }

            var url = Url.Action("Trocas", "Trocas");

            return(Json(new { insert = inserts_ok, url }, JsonRequestBehavior.AllowGet));
        }
Exemplo n.º 4
0
        public JsonResult Remove(TradeDTO[] trade)
        {
            bool   deleted = false;
            string text    = "";

            if (TradeBLL.Remove(trade))
            {
                deleted = true;
                text    = trade.Length > 1 ? "Removidos" : "Removido";
                text   += $" {trade.Length} ";
                text   += trade.Length > 1 ? "transações" : "transação";

                HistoricDTO hist = new HistoricDTO
                {
                    Data      = DateTime.Now.Date,
                    UserId    = CookiesControll.UserAuthenticationInfo().Name,
                    Descricao = text
                };

                deleted = HistoricBLL.RegisterHistoric(hist);
            }

            return(Json(new { deleted, url = Url.Action("Trocas", "Trocas") }, JsonRequestBehavior.AllowGet));
        }
Exemplo n.º 5
0
 public static bool RegisterHistoric(HistoricDTO hist) =>
 HistoricDAO.RegisterHistoric(hist);