public ActionResult AddNew(AddCorridorVM vm) { using (var context = new Jacobs_PlayPenEntities()) { var corridor = new Corridor(); corridor.Description = vm.corridorDescription; corridor.Name = vm.corridorName; context.Corridors.Add(corridor); context.SaveChanges(); foreach (var detector in vm.detectorNumbers) { try { var id = context.Detectors.Where(x => x.det_num == detector).FirstOrDefault().ID; var corridorDetector = new CorridorDetector(); corridorDetector.detectorId = id; corridorDetector.corridorId = corridor.id; context.CorridorDetectors.Add(corridorDetector); } catch (Exception ex) { throw; } } context.SaveChanges(); return(Json(corridor, JsonRequestBehavior.AllowGet)); } }
public ActionResult GetCorridors() { using (var context = new Jacobs_PlayPenEntities()) { var corridors = context.Corridors.ToList(); var corridorVMs = new List <CorridorVM>(); foreach (var corridor in corridors) { var corridorVM = new CorridorVM(); corridorVM.id = corridor.id; corridorVM.Description = corridor.Description; corridorVM.Name = corridor.Name; corridorVM.Year = corridor.Year; var corridorDetectors = context.CorridorDetectors.Where(x => x.corridorId == corridor.id).Select(x => x.detectorId).ToList(); var detectors = context.Detectors.Where(x => corridorDetectors.Contains(x.ID)).ToList(); corridorVM.Detectors = detectors; corridorVMs.Add(corridorVM); } return(Json(corridorVMs, JsonRequestBehavior.AllowGet)); } }
public JsonResult GetDetectors() { using (var context = new Jacobs_PlayPenEntities()) { var data = context.Detectors.ToList(); return(Json(data, JsonRequestBehavior.AllowGet)); } }
public JsonResult GetMiscDetectorData(int det_num, int year) { using (var context = new Jacobs_PlayPenEntities()) { var data = context.detector_MiscData.Where(x => x.detector_number == det_num && x.year == year).FirstOrDefault(); return(Json(data, JsonRequestBehavior.AllowGet)); } }
public JsonResult GetAnnualAvgByLane() { using (var context = new Jacobs_PlayPenEntities()) { var data = context.detector_AvgByLane.ToList(); return(Json(data, JsonRequestBehavior.AllowGet)); } }
public JsonResult AvgHourlyThroughput(int det_num, int year) { using (var context = new Jacobs_PlayPenEntities()) { var data = context.detector_AvgHourlyThroughput.Where(x => x.detector_number == det_num && x.year == year).ToList(); return(Json(data, JsonRequestBehavior.AllowGet)); } }
public JsonResult GetErrors(int det_num, int year) { using (var context = new Jacobs_PlayPenEntities()) { var data = context.vw_LaneErrors.Where(x => x.detector_number == det_num && x.year == year).ToList(); return(Json(data, JsonRequestBehavior.AllowGet)); } }
public ActionResult GetUsers([DataSourceRequest] DataSourceRequest request) { using (var context = new Jacobs_PlayPenEntities()) { var users = GetAppUsers(); return(Json(users.ToDataSourceResult(request), JsonRequestBehavior.AllowGet)); } }
public List <ApplicationRole> GetRoles() { using (var context = new Jacobs_PlayPenEntities()) { context.Configuration.ProxyCreationEnabled = false; var roles = context.ApplicationRoles.ToList(); return(roles); } }
private string GetRoleByDomainName(string name) { using (var context = new Jacobs_PlayPenEntities()) { var currentUser = context.ApplicationUsers.Where(x => x.domainName == name.Replace("AZMAG\\", "")).FirstOrDefault(); if (currentUser == null) { return("Unknown"); } var currentRole = currentUser.ApplicationRole.name; return(currentRole); } }
public ActionResult DeleteUser([DataSourceRequest] DataSourceRequest request, UserViewModel ur) { using (var context = new Jacobs_PlayPenEntities()) { var user = context.ApplicationUsers.Include("ApplicationRole").Where(x => x.domainName == ur.domainName).FirstOrDefault(); var entry = context.Entry(user); if (entry.State == EntityState.Detached) { context.ApplicationUsers.Attach(user); } context.ApplicationUsers.Remove(user); context.SaveChanges(); return(Json(new[] { user }.ToDataSourceResult(request, ModelState))); } }
public ActionResult CreateUser([DataSourceRequest] DataSourceRequest request, UserViewModel ur) { using (var context = new Jacobs_PlayPenEntities()) { var user = new ApplicationUser(); user.RoleId = ur.roleId; user.domainName = ur.domainName; var entry = context.Entry(user); if (entry.State == EntityState.Detached) { context.ApplicationUsers.Attach(user); } context.ApplicationUsers.Add(user); context.SaveChanges(); return(Json(new[] { user }.ToDataSourceResult(request, ModelState))); } }
private List <UserViewModel> GetAppUsers() { using (var context = new Jacobs_PlayPenEntities()) { var userRoleList = new List <UserViewModel>(); var users = context.ApplicationUsers.Include("ApplicationRole").ToList(); foreach (var user in users) { var adUser = GetADUser(user.domainName); var userRole = new UserViewModel(); userRole.domainName = user.domainName; userRole.name = adUser.firstName + " " + adUser.lastName; userRole.roleName = user.ApplicationRole.name; userRole.roleId = user.RoleId; userRoleList.Add(userRole); } return(userRoleList); } }
public ActionResult UpdateUser([DataSourceRequest] DataSourceRequest request, UserViewModel ur) { using (var context = new Jacobs_PlayPenEntities()) { context.Configuration.ProxyCreationEnabled = false; var user = context.ApplicationUsers.Include("ApplicationRole").Where(x => x.domainName == ur.domainName).FirstOrDefault(); user.RoleId = ur.roleId; var newRole = context.ApplicationRoles.Where(x => x.id == ur.roleId).FirstOrDefault(); ur.roleName = newRole.name; var entry = context.Entry(user); if (entry.State == EntityState.Detached) { context.ApplicationUsers.Attach(user); } context.SaveChanges(); return(Json(new[] { ur }.ToDataSourceResult(request, ModelState))); } }
public JsonResult GetErrorData(int det_num, int year) { using (var context = new Jacobs_PlayPenEntities()) { var data = context.vw_Errors.Where(x => x.detector_number == det_num && x.year == year) .GroupBy(x => x.detector_number) .Select(y => new { speed_error = y.Sum(x => x.speed_error == true ? 1 : 0), volume_error = y.Sum(x => x.volume_error == true ? 1 : 0), occupancy_error = y.Sum(x => x.occupancy_error == true ? 1 : 0), zeros_error = y.Sum(x => x.zeros_error == true ? 1 : 0), difference_error = y.Sum(x => x.difference_error == true ? 1 : 0) }).FirstOrDefault(); var totalRows = context.vw_RawData.Where(x => x.detector_number == det_num && x.year == year).Count(); var list = new List <dynamic>(); var speed = new { value = data.speed_error, pct = (float)data.speed_error / (float)totalRows, label = "Speed" }; var volume = new { value = data.volume_error, pct = (float)data.volume_error / (float)totalRows, label = "Volume" }; var occupancy = new { value = data.occupancy_error, pct = (float)data.occupancy_error / (float)totalRows, label = "Occupancy" }; var zeros = new { value = data.zeros_error, pct = (float)data.zeros_error / (float)totalRows, label = "Zeros" }; var difference = new { value = data.difference_error, pct = (float)data.difference_error / (float)totalRows, label = "Difference" }; list.Add(speed); list.Add(volume); list.Add(occupancy); list.Add(zeros); list.Add(difference); return(Json(list, JsonRequestBehavior.AllowGet)); } }