Exemplo n.º 1
0
        public ActionResult LogIn(string Email, string Password)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    AccountRepository _repository = new AccountRepository();

                    Account _account = new Account();
                    _account = _repository.GetAccount(Email, Password);

                    if (_account != null)
                    {
                        Session.Add("Account", _account);

                        return RedirectToAction("Index", "Home");
                    }
                    else
                    {
                        TempData["AlertLogin"] = "******";
                        return RedirectToAction("Index", "Access");
                    }
                }

                return View();
            }
            catch (System.Exception)
            {
                TempData["AlertLogin"] = "******";
                return View("Index", "Access");
            }
        }
Exemplo n.º 2
0
 public void DetailAccount(int id)
 {
     var _account = (Account)Session["Account"];
     if (_account != null)
     {
         try
         {
             Account _a = new Account();
             _a = _repository.GetById(id);
             ViewBag.Account = _a;
         }
         catch (Exception e)
         {
             throw new Exception("Error: " + e.Message);
         }
     }
     else
     {
         RedirectToAction("Index", "Access");
     }
 }
Exemplo n.º 3
0
 public ActionResult Insert(Account a)
 {
     if (ModelState.IsValid)
     {
         try
         {
             IEnumerable<Account> _listAccounts = _repository.GetAll().Where(l => l.Email == a.Email);
             if (_listAccounts.Count() > 0)
             {
                 TempData["AlertLogin"] = "******";
                 return RedirectToAction("Index", "Access");
             }
             else
             {
                 a.Password = Cryptography.Encrypt(a.Password);
                 _repository.Add(a);
             }
         }
         catch (Exception)
         {
             TempData["AlertLogin"] = "******";
             return RedirectToAction("Index", "Access");
         }
         TempData["AlertLogin"] = "******";
         return RedirectToAction("Index", "Access");
     }
     return View(a);
 }
Exemplo n.º 4
0
 public ActionResult Edit(Account a)
 {
     var _account = (Account)Session["Account"];
     if (_account != null)
     {
         if (ModelState.IsValid)
         {
             try
             {
                 if (a.Password.ToString() != _account.Password.ToString())
                 {
                     a.Password = Cryptography.Encrypt(a.Password);
                 }
                 _repository.Update(a);
             }
             catch (Exception)
             {
                 TempData["AlertMessage"] = "Erro: Ocorreu um erro ao atualizar o registro";
                 return RedirectToAction("Index");
             }
             TempData["AlertMessage"] = "Registro atualizado com sucesso.";
             return RedirectToAction("Index");
         }
         return View(a);
     }
     else
     {
         return View("Index", "Access");
     }
 }
 public void LoadCreditCards()
 {
     try
     {
         Infra.Models.CreditCard c = new Infra.Models.CreditCard();
         Account _account = new Account();
         _account = (Account)Session["Account"];
         ViewBag.CreditCards = _repository.GetCardsByAccount(_account.Id);
     }
     catch (Exception e)
     {
         throw new Exception("Error: " + e.Message);
     }
 }