Automated teller machine emulation.
using System;
using System.Web.Mvc;
using SergeyDrozdovATM.BLL;
using SergeyDrozdovATM.Web.Models;
namespace SergeyDrozdovATM.Web.Controllers
{
[Authentication]
public class AccountController : Controller
{
[AllowAnonymous]
public ActionResult Login(string returnUrl)
{
ViewBag.ReturnUrl = returnUrl;
return View();
}
[HttpPost]
[AllowAnonymous]
[ValidateAntiForgeryToken]
public ActionResult Login(UserViewModel model, string returnUrl)
{
if (!ModelState.IsValid)
{
return View(model);
}
try
{
var userService = new UserService();
var userInfo = userService.GetUserByLoginAndPIN(Convert.ToInt32(model.Login), Convert.ToInt32(model.PIN));
if (userInfo != null)
{
Session["LoggedUser"] = userInfo;
return RedirectToAction("Index", "Home");
}
}
catch (Exception ex)
{
Session["LoggedUser"] = null;
ModelState.AddModelError("", ex.Message);
return View(model);
}
return View(model);
}
[AllowAnonymous]
public ActionResult LogOff()
{
Session["LoggedUser"] = null;
return RedirectToAction("Index", "Home");
}
}
}