public ActionResult Login(LoginModel model) { if (ModelState.IsValid) { var userModel = new UserAudit { CompanyId = model.CompanyId, Login = model.Login, Password = model.Password, SessionId = model.SessionId, }; if (ContextManager.Authorize(userModel)) { var userToUpdate = ContextManager.GetCompanyUser(model.CompanyId); if (userToUpdate != null) { userToUpdate.LastAuthorization = DateTime.Now; userToUpdate.SessionId = model.SessionId; ContextManager.SaveUserAudit(userToUpdate); } return(RedirectToAction("Details", "Company", new { id = model.CompanyId })); } else { model.Successful = false; ModelState.AddModelError("Login", "Login/Password is wrong"); } } return(View(model)); }
public ActionResult Create(int companyId) { var cookie = Request.Cookies["session-" + companyId]; var companyUser = ContextManager.GetCompanyUser(companyId); if (cookie == null && companyUser != null) { return(RedirectToAction("Login", "Login", new { companyId = companyId })); } else if (cookie != null && companyUser != null) { var sessionId = Guid.Parse(cookie.Value); var userAudit = ContextManager.GetUserBySession(sessionId); if (!ContextManager.Authorize(userAudit)) { return(RedirectToAction("Login", "Login", new { companyId = companyId })); } } Employee model = new Employee { CompanyId = companyId, }; return(View(model)); }
public ActionResult Delete(int id) { var model = ContextManager.GetEmployeeById(id); var cookie = Request.Cookies["session-" + model.CompanyId]; var companyUser = ContextManager.GetCompanyUser(model.CompanyId); if (cookie == null && companyUser != null) { return(RedirectToAction("Login", "Login", new { companyId = model.CompanyId })); } else if (cookie != null && companyUser != null) { var sessionId = Guid.Parse(cookie.Value); var userAudit = ContextManager.GetUserBySession(sessionId); if (!ContextManager.Authorize(userAudit)) { return(RedirectToAction("Login", "Login", new { companyId = model.CompanyId })); } } ContextManager.DeleteEmployee(id); return(RedirectToAction("Details", "Company", new { id = model.CompanyId })); }
public ActionResult DeleteCompany(int id) { var cookie = Request.Cookies["session-" + id]; var companyUser = ContextManager.GetCompanyUser(id); if (cookie == null && companyUser != null) { return(RedirectToAction("Login", "Login", new { companyId = id })); } else if (cookie != null && companyUser != null) { var sessionId = Guid.Parse(cookie.Value); var userAudit = ContextManager.GetUserBySession(sessionId); if (!ContextManager.Authorize(userAudit)) { return(RedirectToAction("Login", "Login", new { companyId = id })); } } var model = ContextManager.GetCompanyById(id); ContextManager.DeleteCompany(id); return(RedirectToAction("List")); }
public ActionResult EditCompany(int id) { var cookie = Request.Cookies["session-" + id]; var companyUser = ContextManager.GetCompanyUser(id); if (cookie == null && companyUser != null) { return(RedirectToAction("Login", "Login", new { companyId = id })); } else if (cookie != null && companyUser != null) { var sessionId = Guid.Parse(cookie.Value); var userAudit = ContextManager.GetUserBySession(sessionId); if (!ContextManager.Authorize(userAudit)) { return(RedirectToAction("Login", "Login", new { companyId = id })); } } var model = new CompanyCreateEditModel(); var company = ContextManager.GetCompanyById(id); model.Id = company.Id; model.Name = company.Name; model.Budget = company.Budget; model.AddressLine = company.AddressLine; model.CompanyId = company.CompanyId; model.OwnerId = company.OwnerId; if (companyUser != null) { model.Login = companyUser.Login; model.Password = companyUser.Password; } return(View(model)); }
public ActionResult Authorize(Guid sessionId) { var model = ContextManager.GetUserBySession(sessionId); return(Json(ContextManager.Authorize(model), JsonRequestBehavior.AllowGet)); }