示例#1
0
        //// GET: SPMUsers/Details/5
        //public ActionResult Details(string id)
        //{
        //    if (id == null)
        //    {
        //        return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
        //    }
        //    SPMUser sPMUser = db.SPMUsers.Find(id);
        //    if (sPMUser == null)
        //    {
        //        return HttpNotFound();
        //    }
        //    return View(sPMUser);
        //}


        // GET: SPMUsers/Edit/5
        public ActionResult Edit(string id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Models.UserViewModel user = new Models.UserViewModel();

            using (var context = new MOE.Common.Models.SPM())
            {
                List <string> roles;
                var           userStore   = new UserStore <SPMUser>(context);
                var           userManager = new UserManager <SPMUser>(userStore);
                var           roleStore   = new RoleStore <IdentityRole>(context);
                var           roleManager = new RoleManager <IdentityRole>(roleStore);
                user.User = userManager.Users.Where(u => u.Id == id).FirstOrDefault();
                foreach (IdentityUserRole role in user.User.Roles)
                {
                    user.Roles.Add(roleManager.Roles.Where(r => r.Id == role.RoleId).First().Name);
                }
                roles         = (from r in roleManager.Roles select r.Name).ToList();
                ViewBag.Roles = new SelectList(roles.OrderBy(r => r));
            }
            if (user == null)
            {
                return(HttpNotFound());
            }
            return(View(user));
        }
示例#2
0
 public ActionResult Edit(Models.UserViewModel sPMUser)
 {
     if (ModelState.IsValid)
     {
         SPMUser user;
         using (var context = new MOE.Common.Models.SPM())
         {
             try
             {
                 var userStore   = new UserStore <SPMUser>(context);
                 var userManager = new UserManager <SPMUser>(userStore);
                 user = userManager.Users.Where(u => u.Id == sPMUser.User.Id).FirstOrDefault();
                 user.ReceiveAlerts = sPMUser.User.ReceiveAlerts;
                 user.Email         = sPMUser.User.Email;
                 user.UserName      = sPMUser.User.Email;
                 context.SaveChanges();
             }
             catch (Exception ex)
             {
                 return(Content("<h1>" + ex.Message + "</h1>"));
             }
         }
         return(RedirectToAction("Index"));
     }
     return(View(sPMUser));
 }
示例#3
0
 public ActionResult AddRoleToUser(string roleName, string userName)
 {
     using (var context = new MOE.Common.Models.SPM())
     {
         var roleStore   = new RoleStore <IdentityRole>(context);
         var roleManager = new RoleManager <IdentityRole>(roleStore);
         var userStore   = new UserStore <SPMUser>(context);
         var userManager = new UserManager <SPMUser>(userStore);
         var user        = userManager.FindByName(userName);
         if (user == null)
         {
             return(Content("User not found"));
         }
         var role = roleManager.FindByName(roleName);
         if (role == null)
         {
             return(Content("Role not found"));
         }
         if (userManager.IsInRole(user.Id, role.Name))
         {
             return(Content("This user already has this role assigned"));
         }
         userManager.AddToRole(user.Id, role.Name);
         context.SaveChanges();
         return(Content("Role Added"));
     }
 }
示例#4
0
 public ActionResult RemoveRoleFromUser(string roleName, string userName)
 {
     using (var context = new MOE.Common.Models.SPM())
     {
         var roleStore   = new RoleStore <IdentityRole>(context);
         var roleManager = new RoleManager <IdentityRole>(roleStore);
         var userStore   = new UserStore <SPMUser>(context);
         var userManager = new UserManager <SPMUser>(userStore);
         var user        = userManager.FindByName(userName);
         if (user == null)
         {
             return(Content("User not found"));
         }
         var role = roleManager.FindByName(roleName);
         if (role == null)
         {
             return(Content("Role not found"));
         }
         if (!userManager.IsInRole(user.Id, role.Name))
         {
             return(Content("This user does not have this role assigned"));
         }
         else
         {
             userManager.RemoveFromRole(user.Id, role.Name);
             context.SaveChanges();
             return(Content("Role Removed"));
         }
     }
 }
示例#5
0
文件: Program.cs 项目: gmonk/ATSPM
 public ImportChecker()
 {
     StartTime       = DateTime.Now.AddMinutes(-30);
     EndTime         = DateTime.Now;
     ThereIsAProblem = false;
     try
     {
         CELRepository = MOE.Common.Models.Repositories.ControllerEventLogRepositoryFactory.Create();
         _db           = new SPM();
         var testSignals = _db.Signals.Take(1).FirstOrDefault();
     }
     catch
     {
         ThereIsAProblem = true;
         message.Body    = "The import checker could not find the database.";
     }
     if (_db != null && CELRepository != null && !ThereIsAProblem)
     {
         List <MOE.Common.Models.ControllerType> TypesInUse = FindControllerTypesInUse();
         foreach (var t in TypesInUse)
         {
             CheckControllerEventLogByControllerType(t);
         }
         CheckSpeedRecords();
         CheckSpeedService();
     }
     if (ThereIsAProblem)
     {
         CreateAndSendEmail();
     }
 }
示例#6
0
        public ActionResult DeleteConfirmed(string id)
        {
            SPMUser user;

            using (var context = new MOE.Common.Models.SPM())
            {
                var userStore   = new UserStore <SPMUser>(context);
                var userManager = new UserManager <SPMUser>(userStore);
                user = userManager.Users.Where(u => u.Id == id).FirstOrDefault();
                userManager.Delete(user);
            }
            return(RedirectToAction("Index"));
        }
示例#7
0
        public ActionResult RoleCreate(string roleName)
        {
            using (var context = new MOE.Common.Models.SPM())
            {
                var roleStore   = new RoleStore <IdentityRole>(context);
                var roleManager = new RoleManager <IdentityRole>(roleStore);

                roleManager.Create(new IdentityRole(roleName));
                context.SaveChanges();
            }

            ViewBag.ResultMessage = "Role created successfully !";
            return(RedirectToAction("RoleIndex", "Account"));
        }
示例#8
0
        public ActionResult RoleIndex()
        {
            List <string> roles;

            using (var context = new MOE.Common.Models.SPM())
            {
                var roleStore   = new RoleStore <IdentityRole>(context);
                var roleManager = new RoleManager <IdentityRole>(roleStore);

                roles = (from r in roleManager.Roles select r.Name).ToList();
            }

            return(View(roles.ToList()));
        }
示例#9
0
        public ActionResult DeleteRoleForUser(string userName, string roleName)
        {
            List <string> userRoles;
            List <string> roles;
            List <string> users;

            using (var context = new MOE.Common.Models.SPM())
            {
                var roleStore   = new RoleStore <IdentityRole>(context);
                var roleManager = new RoleManager <IdentityRole>(roleStore);

                roles = (from r in roleManager.Roles select r.Name).ToList();

                var userStore   = new UserStore <SPMUser>(context);
                var userManager = new UserManager <SPMUser>(userStore);

                users = (from u in userManager.Users select u.UserName).ToList();

                var user = userManager.FindByName(userName);
                if (user == null)
                {
                    throw new Exception("User not found!");
                }

                if (userManager.IsInRole(user.Id, roleName))
                {
                    userManager.RemoveFromRole(user.Id, roleName);
                    context.SaveChanges();

                    ViewBag.ResultMessage = "Role removed from this user successfully !";
                }
                else
                {
                    ViewBag.ResultMessage = "This user doesn't belong to selected role.";
                }

                var userRoleIds = (from r in user.Roles select r.RoleId);
                userRoles = (from id in userRoleIds
                             let r = roleManager.FindById(id)
                                     select r.Name).ToList();
            }

            ViewBag.RolesForThisUser = userRoles;
            ViewBag.Roles            = new SelectList(roles);
            ViewBag.Users            = new SelectList(users);
            return(View("RoleAddToUser"));
        }
示例#10
0
        public static void PopulateApproachesWithDetectors(MOE.Common.Models.SPM db)
        {
            foreach (var signal in db.Signals)
            {
                signal.Approaches = (from r in db.Approaches
                                     where r.VersionID == signal.VersionID
                                     select r).ToList();

                int i = 1;
                foreach (var appr in signal.Approaches)
                {
                    MOE.Common.Models.Detector a = new Detector()
                    {
                        ApproachID = appr.ApproachID,

                        DetChannel          = appr.ProtectedPhaseNumber,
                        DetectionHardwareID = 1,
                        DateAdded           = DateTime.Today,
                        LaneNumber          = 1,
                        MovementTypeID      = 1,
                        DetectorID          = appr.SignalID + "00" + appr.ProtectedPhaseNumber.ToString(),
                    };

                    db.Detectors.Add(a);


                    i++;
                }
            }
            try
            {
                db.SaveChanges();
            }
            catch (DbEntityValidationException dbEx)
            {
                foreach (var validationErrors in dbEx.EntityValidationErrors)
                {
                    foreach (var validationError in validationErrors.ValidationErrors)
                    {
                        Trace.TraceInformation("Property: {0} Error: {1}",
                                               validationError.PropertyName,
                                               validationError.ErrorMessage);
                    }
                }
            }
        }
示例#11
0
        public ActionResult RoleAddToUser(string roleName, string userName)
        {
            List <string> roles;
            List <string> users;

            using (var context = new MOE.Common.Models.SPM())
            {
                var roleStore   = new RoleStore <IdentityRole>(context);
                var roleManager = new RoleManager <IdentityRole>(roleStore);

                var userStore   = new UserStore <SPMUser>(context);
                var userManager = new UserManager <SPMUser>(userStore);

                users = (from u in userManager.Users select u.UserName).ToList();

                var user = userManager.FindByName(userName);
                if (user == null)
                {
                    throw new Exception("User not found!");
                }

                var role = roleManager.FindByName(roleName);
                if (role == null)
                {
                    throw new Exception("Role not found!");
                }

                if (userManager.IsInRole(user.Id, role.Name))
                {
                    ViewBag.ResultMessage = "This user already has the role specified !";
                }
                else
                {
                    userManager.AddToRole(user.Id, role.Name);
                    context.SaveChanges();

                    ViewBag.ResultMessage = "Username added to the role succesfully !";
                }

                roles = (from r in roleManager.Roles select r.Name).ToList();
            }

            ViewBag.Roles = new SelectList(roles);
            ViewBag.Users = new SelectList(users);
            return(View());
        }
示例#12
0
        // GET: SPMUsers/Delete/5
        public ActionResult Delete(string id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            SPMUser user;

            using (var context = new MOE.Common.Models.SPM())
            {
                var userStore   = new UserStore <SPMUser>(context);
                var userManager = new UserManager <SPMUser>(userStore);
                user = userManager.Users.Where(u => u.Id == id).FirstOrDefault();
            }
            if (user == null)
            {
                return(HttpNotFound());
            }
            return(View(user));
        }
示例#13
0
        public ActionResult RoleAddToUser()
        {
            List <string> roles;
            List <string> users;

            using (var context = new MOE.Common.Models.SPM())
            {
                var roleStore   = new RoleStore <IdentityRole>(context);
                var roleManager = new RoleManager <IdentityRole>(roleStore);

                var userStore   = new UserStore <SPMUser>(context);
                var userManager = new UserManager <SPMUser>(userStore);

                users = (from u in userManager.Users select u.UserName).ToList();
                roles = (from r in roleManager.Roles select r.Name).ToList();
            }

            ViewBag.Roles = new SelectList(roles);
            ViewBag.Users = new SelectList(users);
            return(View());
        }
示例#14
0
        public void PopulateSignal(MOE.Common.Models.SPM db)
        {
            for (int i = 1; i < 6; i++)
            {
                MOE.Common.Models.Signal s = new Signal();

                s.SignalID = "10" + i.ToString();

                s.Start            = s.FirstDate;
                s.PrimaryName      = "Primary: " + i.ToString();
                s.SecondaryName    = "Secondary: " + i.ToString();
                s.Note             = "Create Dummy";
                s.IPAddress        = "10.10.10.10";
                s.Latitude         = "0.01";
                s.Longitude        = "0.01";
                s.ControllerTypeID = 1;
                s.RegionID         = 1;
                s.Enabled          = true;

                s.VersionActionId = 10;

                db.Signals.Add(s);
            }
            try
            {
                db.SaveChanges();
            }
            catch (DbEntityValidationException dbEx)
            {
                foreach (var validationErrors in dbEx.EntityValidationErrors)
                {
                    foreach (var validationError in validationErrors.ValidationErrors)
                    {
                        Trace.TraceInformation("Property: {0} Error: {1}",
                                               validationError.PropertyName,
                                               validationError.ErrorMessage);
                    }
                }
            }
        }
示例#15
0
        public ActionResult GetRoles(string userName)
        {
            if (!string.IsNullOrWhiteSpace(userName))
            {
                List <string> userRoles;
                List <string> roles;
                List <string> users;
                using (var context = new MOE.Common.Models.SPM())
                {
                    var roleStore   = new RoleStore <IdentityRole>(context);
                    var roleManager = new RoleManager <IdentityRole>(roleStore);

                    roles = (from r in roleManager.Roles select r.Name).ToList();

                    var userStore   = new UserStore <SPMUser>(context);
                    var userManager = new UserManager <SPMUser>(userStore);

                    users = (from u in userManager.Users select u.UserName).ToList();

                    var user = userManager.FindByName(userName);
                    if (user == null)
                    {
                        throw new Exception("User not found!");
                    }

                    var userRoleIds = (from r in user.Roles select r.RoleId);
                    userRoles = (from id in userRoleIds
                                 let r = roleManager.FindById(id)
                                         select r.Name).ToList();
                }

                ViewBag.Roles            = new SelectList(roles);
                ViewBag.Users            = new SelectList(users);
                ViewBag.RolesForThisUser = userRoles;
            }

            return(View("RoleAddToUser"));
        }
示例#16
0
        // GET: SPMUsers
        public ActionResult Index()
        {
            List <Models.UserViewModel> users = new List <Models.UserViewModel>();

            using (var context = new MOE.Common.Models.SPM())
            {
                var userStore   = new UserStore <SPMUser>(context);
                var userManager = new UserManager <SPMUser>(userStore);
                var roleStore   = new RoleStore <IdentityRole>(context);
                var roleManager = new RoleManager <IdentityRole>(roleStore);
                foreach (SPMUser user in userStore.Users.OrderBy(u => u.Email).ToList())
                {
                    Models.UserViewModel userViewModel = new Models.UserViewModel();
                    userViewModel.User = user;
                    foreach (IdentityUserRole role in user.Roles)
                    {
                        userViewModel.Roles.Add(roleManager.Roles.Where(r => r.Id == role.RoleId).First().Name);
                    }
                    users.Add(userViewModel);
                }
            }
            return(View(users));
        }
示例#17
0
        private void CreateAndSendEmail()
        {
            System.Net.Mail.MailMessage message = new System.Net.Mail.MailMessage();
            MOE.Common.Models.SPM       db      = new MOE.Common.Models.SPM();
            var            userStore            = new UserStore <SPMUser>(db);
            var            userManager          = new UserManager <SPMUser>(userStore);
            List <SPMUser> users = (from u in userManager.Users
                                    where u.ReceiveAlerts == true
                                    select u).ToList();

            foreach (SPMUser user in users)
            {
                message.To.Add(user.Email);
            }
            message.To.Add(Settings.DefaultEmailAddress);
            message.Subject = "ATSPM Alerts for " + ScanDate.ToShortDateString();
            message.From    = new System.Net.Mail.MailAddress(Settings.FromEmailAddress);
            string missingErrors  = SortAndAddToMessage(MissingRecords);
            string forceErrors    = SortAndAddToMessage(ForceOffErrors);
            string maxErrors      = SortAndAddToMessage(MaxOutErrors);
            string countErrors    = SortAndAddToMessage(LowHitCountErrors);
            string stuckpedErrors = SortAndAddToMessage(StuckPedErrors);

            if (MissingRecords.Count > 0 && missingErrors != "")
            {
                message.Body += " \n --The following signals had too few records in the database on ";
                if (Settings.WeekdayOnly && ScanDate.DayOfWeek == DayOfWeek.Monday)
                {
                    message.Body += ScanDate.AddDays(-3).Date.ToShortDateString() + ": \n";
                }
                else
                {
                    message.Body += ScanDate.AddDays(-1).Date.ToShortDateString() + ": \n";
                }
                message.Body += missingErrors;
            }
            else
            {
                message.Body += "\n --No new missing record errors were found on ";
                if (Settings.WeekdayOnly && ScanDate.DayOfWeek == DayOfWeek.Monday)
                {
                    message.Body += ScanDate.AddDays(-3).Date.ToShortDateString() + ": \n";
                }
                else
                {
                    message.Body += ScanDate.AddDays(-1).Date.ToShortDateString() + ": \n";
                }
            }

            if (ForceOffErrors.Count > 0 && forceErrors != "")
            {
                message.Body += " \n --The following signals had too many force off occurrences between " +
                                Settings.ScanDayStartHour.ToString() + ":00 and " +
                                Settings.ScanDayEndHour.ToString() + ":00: \n";
                message.Body += forceErrors;
            }
            else
            {
                message.Body += "\n --No new force off errors were found between " +
                                Settings.ScanDayStartHour.ToString() + ":00 and " +
                                Settings.ScanDayEndHour.ToString() + ":00: \n";
            }

            if (MaxOutErrors.Count > 0 && maxErrors != "")
            {
                message.Body += " \n --The following signals had too many max out occurrences between " +
                                Settings.ScanDayStartHour.ToString() + ":00 and " +
                                Settings.ScanDayEndHour.ToString() + ":00: \n";
                message.Body += maxErrors;
            }
            else
            {
                message.Body += "\n --No new max out errors were found between " +
                                Settings.ScanDayStartHour.ToString() + ":00 and " +
                                Settings.ScanDayEndHour.ToString() + ":00: \n";
            }

            if (LowHitCountErrors.Count > 0 && countErrors != "")
            {
                message.Body += " \n --The following signals had unusually low advanced detection counts on ";
                if (Settings.WeekdayOnly && ScanDate.DayOfWeek == DayOfWeek.Monday)
                {
                    message.Body += ScanDate.AddDays(-3).ToShortDateString() + " between ";
                }
                else
                {
                    message.Body += ScanDate.AddDays(-1).ToShortDateString() + " between ";
                }
                message.Body += Settings.PreviousDayPMPeakStart.ToString() + ":00 and " +
                                Settings.PreviousDayPMPeakEnd.ToString() + ":00: \n";
                message.Body += countErrors;
            }
            else
            {
                message.Body += "\n --No new low advanced detection count errors on ";
                if (Settings.WeekdayOnly && ScanDate.DayOfWeek == DayOfWeek.Monday)
                {
                    message.Body += ScanDate.AddDays(-3).ToShortDateString() + " between ";
                }
                else
                {
                    message.Body += ScanDate.AddDays(-1).ToShortDateString() + " between ";
                }
                message.Body += Settings.PreviousDayPMPeakStart.ToString() + ":00 and " +
                                Settings.PreviousDayPMPeakEnd.ToString() + ":00: \n";
            }
            if (StuckPedErrors.Count > 0 && stuckpedErrors != "")
            {
                message.Body += " \n --The following signals have high pedestrian activation occurrences between " +
                                Settings.ScanDayStartHour.ToString() + ":00 and " +
                                Settings.ScanDayEndHour.ToString() + ":00: \n";
                message.Body += stuckpedErrors;
            }
            else
            {
                message.Body += "\n --No new high pedestrian activation errors between " +
                                Settings.ScanDayStartHour.ToString() + ":00 and " +
                                Settings.ScanDayEndHour.ToString() + ":00: \n";
            }

            SendMessage(message);
        }
示例#18
0
        public void PopulateSignalsWithApproaches(MOE.Common.Models.SPM db)
        {
            int i = 1;

            foreach (var s in db.Signals)
            {
                Approach a = new Approach
                {
                    ApproachID    = (s.VersionID * 1020) + 1,
                    Description   = "NB Approach for Signal " + s.SignalID,
                    DirectionType = (from r in db.DirectionTypes
                                     where r.Abbreviation == "NB"
                                     select r).FirstOrDefault(),



                    ProtectedPhaseNumber = 2,
                    SignalID             = s.SignalID,
                    MPH       = 40,
                    VersionID = s.VersionID,
                    Signal    = s
                };

                db.Approaches.Add(a);

                Approach b = new Approach
                {
                    ApproachID    = (s.VersionID * 1040) + 1,
                    Description   = "SB Approach for Signal " + s.SignalID,
                    DirectionType = (from r in db.DirectionTypes
                                     where r.Abbreviation == "SB"
                                     select r).FirstOrDefault(),

                    ProtectedPhaseNumber = 4,
                    SignalID             = s.SignalID,
                    MPH       = 40,
                    VersionID = s.VersionID,
                    Signal    = s
                };

                db.Approaches.Add(b);

                Approach c = new Approach
                {
                    ApproachID    = (s.VersionID * 1060) + 1,
                    Description   = "SB Approach for Signal " + s.SignalID,
                    DirectionType = (from r in db.DirectionTypes
                                     where r.Abbreviation == "EB"
                                     select r).FirstOrDefault(),

                    ProtectedPhaseNumber = 6,
                    SignalID             = s.SignalID,
                    MPH       = 40,
                    VersionID = s.VersionID,
                    Signal    = s
                };

                db.Approaches.Add(c);

                Approach d = new Approach
                {
                    Description   = "SB Approach for Signal " + s.SignalID,
                    DirectionType = (from r in db.DirectionTypes
                                     where r.Abbreviation == "WB"
                                     select r).FirstOrDefault(),

                    ProtectedPhaseNumber = 8,
                    SignalID             = s.SignalID,
                    MPH       = 40,
                    VersionID = s.VersionID,
                    Signal    = s
                };

                db.Approaches.Add(d);

                i++;
            }

            try
            {
                db.SaveChanges();
            }
            catch (DbEntityValidationException dbEx)
            {
                foreach (var validationErrors in dbEx.EntityValidationErrors)
                {
                    foreach (var validationError in validationErrors.ValidationErrors)
                    {
                        Trace.TraceInformation("Property: {0} Error: {1}",
                                               validationError.PropertyName,
                                               validationError.ErrorMessage);
                    }
                }
            }
        }