public ActionResult Login(Login login, string ReturnURL = "") { String message = ""; using (mmpEntities mP = new mmpEntities()) { var v = mP.users.Where(a => a.user_email == login.email && a.user_status == "active").FirstOrDefault(); if (v != null) { string Roles = UserID_RoleID.getRole(v.employee_id); //Debug.WriteLine(string.IsNullOrEmpty(login.user_password)); if (string.Compare(Crypto.Hash(login.user_password), v.user_password) == 0) { int timeout = login.RememberMe ? 525600 : 20; // 525600 => 1 year //var ticket = new FormsAuthenticationTicket(login.user_name, login.RememberMe, timeout); var authTicket = new FormsAuthenticationTicket(v.user_id, v.employee_id, DateTime.Now, DateTime.Now.AddMinutes(60), /* expiry */ false, Roles, "/"); string encrypted = FormsAuthentication.Encrypt(authTicket); var cookie = new HttpCookie(FormsAuthentication.FormsCookieName, encrypted); cookie.Expires = DateTime.Now.AddMinutes(60); cookie.HttpOnly = true; Response.Cookies.Add(cookie); //Debug.WriteLine(Roles); if (Url.IsLocalUrl(ReturnURL)) { return(Redirect(ReturnURL)); } else { return(RedirectToAction("Index", "Home")); } } else { ModelState.AddModelError("PasswordERR", "Password is incorrect"); message = "Password is incorrect"; } } else { ModelState.AddModelError("EmailERR", "E-mail does not exist"); message = "E-mail does not exist"; } } ViewBag.Message = message; return(View()); }
// GET: Home public ActionResult Index() { using (mmpEntities mP = new mmpEntities()) { Debug.WriteLine("Here"); Debug.WriteLine(User.Identity.Name); if (User.Identity.IsAuthenticated && UserID_RoleID.getRole(User.Identity.Name) != "admin") { //send them to the AuthenticatedIndex page instead of the index page int user_id = UserID_RoleID.getUserID(); var ts = mP.timesheets.OrderByDescending(x => x.time_my).Where(x => x.timesheet_user == user_id && x.tsmr_extension > DateTime.Now).FirstOrDefault <timesheet>(); //return RedirectToAction("UserTimesheets", "TimeSheet"); if (ts != null) { return(RedirectToAction("TimeSheetEditView", "TimeSheet", new { id = ts.timesheet_id })); } else { return(RedirectToAction("UserTimesheets", "TimeSheet")); } //'@Url.Action("TimeSheetEditView", "TimeSheet")/'+id } else if (User.Identity.IsAuthenticated && UserID_RoleID.getRole(User.Identity.Name) == "admin") { List <string> sectors = new List <string>(); List <int> project_count = new List <int>(); List <DataPoint> dataPoints = new List <DataPoint>(); List <DataPoint> timeSheet_status_count = new List <DataPoint>(); mP.Configuration.ProxyCreationEnabled = false; var usersPerRole = from user in mP.users group user by user.role into userGroup select new { value = userGroup.Key.role_name, count = userGroup.Count(), }; foreach (var item in usersPerRole) { //Debug.WriteLine(item.value); //Debug.WriteLine(item.count); dataPoints.Add(new DataPoint(item.value.ToString().ToUpper(), item.count)); } //var timeSheetCountByStatus = from var projectsPerSector = from pd in mP.project_details group pd by pd.sector into projectGroup select new { value = projectGroup.Key.sector_name, count = projectGroup.Count() }; foreach (var item in projectsPerSector) { sectors.Add(item.value.ToString().ToUpper()); project_count.Add(item.count); } ViewBag.DoughnutDataPoints = JsonConvert.SerializeObject(dataPoints); ViewBag.Sectors = JsonConvert.SerializeObject(sectors); ViewBag.ProjecsCount = JsonConvert.SerializeObject(project_count); //Debug.WriteLine(JsonConvert.SerializeObject(dataPoints)); //Debug.WriteLine(JsonConvert.SerializeObject(sectors)); //Debug.WriteLine(JsonConvert.SerializeObject(project_count)); return(View()); } return(View()); } }