예제 #1
0
 public ActionResult Account(account ChangeAccount, string OldPass)
 {
     if (ModelState.IsValidField("Email") && ModelState.IsValidField("Password"))
     {
         account update;
         try
         {
             update = _DAOFactory.AccountDAO.getByEmail(User.Identity.Name);
             if (update != null)
             {
                 if (OldPass != update.password)
                 {
                     ModelState.AddModelError("Error", "Wrong Password");
                     return View(ChangeAccount);
                 }
                 if (User.Identity.Name.ToLower() != ChangeAccount.email.ToLower())
                 {
                     var accounts = _DAOFactory.AccountDAO.getByEmail(ChangeAccount.email);
                     if (accounts != null)
                     {
                         ModelState.AddModelError("Error", "Email already exists");
                         return View(ChangeAccount);
                     }
                 }
                 ChangeAccount.role = update.role;
                 ChangeAccount.id = update.id;
                 update = ChangeAccount;
                 _DAOFactory.AccountDAO.update(update);
             }
             else
             {
                 return RedirectToAction("Logout");
             }
         }
         catch (Exception ex)
         {
             ModelState.AddModelError("Error", ex.Message);
             return View(ChangeAccount);
         }
         if (User.Identity.IsAuthenticated)
         {
             FormsAuthentication.SignOut();
         }
         FormsAuthentication.SetAuthCookie(update.email, false);
         ViewBag.Account = "Account Updated";
     }
     return View(ChangeAccount);
 }
예제 #2
0
 public ActionResult Account()
 {
     account ChangeAccount = new account();
     try
     {
         account Account = _DAOFactory.AccountDAO.getByEmail(User.Identity.Name);
         if (Account != null)
         {
             ChangeAccount = Account;
         }
     }
     catch (Exception ex)
     {
         ModelState.AddModelError("Error", ex.Message);
     }
     return View(ChangeAccount);
 }