Example #1
0
        public ActionResult Add()
        {
            var cookie      = CookiesControll.UserAuthenticationInfo();
            var genericUser = GenericUserBLL.GetUserById(cookie.Name);

            if (cookie.UserData == "Client")
            {
                if (genericUser.UserID != "null")
                {
                    ViewData["Coins"]      = TradeCoinBLL.ListAll();
                    ViewData["Operations"] = OperationBLL.ListAll();
                    ViewBag.UserId         = genericUser.UserID;
                    return(View());
                }
                else
                {
                    var quitCookie = new HttpCookie(CookiesControll.MasterCookie)
                    {
                        Expires = DateTime.Now.AddDays(-1)
                    };
                    Response.Cookies.Add(quitCookie);

                    FormsAuthentication.SignOut();

                    return(RedirectToAction("SignIn", "Login", new { area = "" }));
                }
            }
            else
            {
                return(RedirectToAction("Index", "Home", new { area = "" }));
            }
        }
Example #2
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));
        }