예제 #1
0
 public S2Importer(S2API api)
 {
     db           = new RSMDataModelDataContext();
     _api         = api;
     ExportSystem = api.ExportSystem;
     ImportSystem = api.ImportSystem;
 }
예제 #2
0
        void UpdateRoles(Person person, List <GridDataRow> roles)
        {
            var context = new RSMDataModelDataContext();

            var thisPersonRoles = from r in context.PeopleRoles
                                  where r.PersonID == person.PersonID
                                  select r;

            if (thisPersonRoles.Count() > 0)
            {
                context.PeopleRoles.DeleteAllOnSubmit(thisPersonRoles);
            }

            context.SubmitChanges();

            PeopleRole role;


            foreach (GridDataRow row in roles)
            {
                role             = new PeopleRole();
                role.RoleID      = int.Parse(row.ID);
                role.PersonID    = person.PersonID;
                role.IsException = (row.Exception != "0");

                person.PeopleRoles.Add(role);
            }



            context.SubmitChanges();
        }
예제 #3
0
 public S2Importer(string connStr, S2API api)
 {
     db           = new RSMDataModelDataContext(connStr);
     _api         = api;
     ExportSystem = api.ExportSystem;
     ImportSystem = api.ImportSystem;
 }
예제 #4
0
        public ActionResult AssignedRoles(int id)
        {
            var    context = new RSMDataModelDataContext();
            Person person  = (from p in context.Persons
                              where p.PersonID == id
                              select p).First();

            var jsonAssLevels = new
            {
                total   = 1,
                page    = 1,
                records = person.PeopleRoles.Count,
                rows    = (
                    from r in person.PeopleRoles
                    select new
                {
                    i = r.ID,
                    cell = new string[] {
                        r.RoleID.ToString(), r.Role.RoleName.ToString(), r.Role.RoleDesc.ToString(), ((r.IsException) ? 1 : 0).ToString()
                    }
                }).ToArray()
            };

            return(Json(jsonAssLevels));
        }
예제 #5
0
        void UpdateRole(int id, string name, string description, List <GridDataRow> levels)
        {
            Role   role;
            var    context = new RSMDataModelDataContext();
            string action  = "modified";

            if (description == null)
            {
                description = "";
            }

            if (id > 0)
            {
                role = (from p in context.Roles
                        where p.RoleID == id
                        select p).Single();
            }
            else
            {
                action = "created";
                role   = new Role();
                context.Roles.InsertOnSubmit(role);
            }

            role.RoleName = name;
            role.RoleDesc = description;

            var thisRoleLevels = from l in context.AccessLevelRoles
                                 where l.RoleID == role.RoleID
                                 select l;

            if (thisRoleLevels.Count() > 0)
            {
                context.AccessLevelRoles.DeleteAllOnSubmit(thisRoleLevels);
            }

            context.SubmitChanges();

            foreach (GridDataRow row in levels)
            {
                AccessLevelRole alr = new AccessLevelRole {
                    AccessLevelID = int.Parse(row.ID), RoleID = role.RoleID
                };

                role.AccessLevelRoles.Add(alr);
            }

            foreach (var p in context.PeopleWithRole(id))
            {
                p.NeedsRulePass = true;
                p.NeedsUpload   = true;
            }

            context.SubmitChanges();



            EventLogger.LogUserActivity(Severity.Informational,
                                        string.Format("{0} {1} role {2}", User.Identity.Name, action, role.RoleName), "");
        }
예제 #6
0
        public ActionResult AssignedRoles(int id)
        {
            if (id == 0)
            {
                return(Json(""));
            }

            var         context = new RSMDataModelDataContext();
            JCLRoleRule rule    = (from r in context.JCLRoleRules
                                   where r.ID == id
                                   select r).Single();

            var jsonAssLevels = new
            {
                total   = 1,
                page    = 1,
                records = rule.JCLRoles.Count,
                rows    = (
                    from r in rule.JCLRoles
                    select new
                {
                    i = r.ID,
                    cell = new string[] {
                        r.RoleID.ToString(), r.Role.RoleName, r.Role.RoleDesc.ToString()
                    }
                }).ToArray()
            };

            return(Json(jsonAssLevels));
        }
예제 #7
0
        //
        // MembershipProvider.UpdateUser - stubbed
        //

        public override void UpdateUser(MembershipUser user)
        {
            Person person = null;
            RSMDataModelDataContext ctx = new RSMDataModelDataContext();

            try
            {
                person = (from p in ctx.Persons
                          where p.PersonID == (int)user.ProviderUserKey
                          select p).Single();
            }
            catch (Exception e)
            {
                WriteToEventLog(e, "UpdateUser");
                return;
            }
            if (person == null)
            {
                return;
            }


            person.LastActivity = user.LastActivityDate;
            person.LastLogin    = DateTime.Now;
            person.LockedOut    = user.IsLockedOut;
            ctx.SubmitChanges();
            return;
        }
예제 #8
0
        public override string[] GetRolesForUser(string username)
        {
            List <string> roles = new List <string>();
            Person        person;

            RSMDataModelDataContext context = new RSMDataModelDataContext();

            try
            {
                person = (from p in context.Persons
                          where p.username == username
                          select p).Single();
            }
            catch (Exception)
            {
                if (username.Equals("admin"))
                {
                    roles.Add("admin");
                }
                return(roles.ToArray());
            }

            roles.Add("user");
            if (person.IsAdmin)
            {
                roles.Add("admin");
            }


            return(roles.ToArray());
        }
예제 #9
0
        public override bool IsUserInRole(string username, string rolename)
        {
            Person person;

            RSMDataModelDataContext context = new RSMDataModelDataContext();

            try
            {
                person = (from p in context.Persons
                          where p.username == username
                          select p).Single();
            }
            catch (Exception)
            {
                if (username.Equals("admin"))
                {
                    return(true);
                }

                return(false);
            }

            if (rolename == "admin")
            {
                return(person.IsAdmin);
            }

            return(true);
        }
예제 #10
0
        public void ControllerSetup()
        {
            EventLogger = new Logger();
            DbContext   = new RSMDataModelDataContext(ConfigurationManager.ConnectionStrings[Artifacts.Constants.ConnectionStringName].ConnectionString);

            OwnedSystem = DbContext.ExternalSystems.FirstOrDefault(x => x.Name == OwnedSystemName);
        }
예제 #11
0
        void UploadAssociates()
        {
            RSMDataModelDataContext db = new RSMDataModelDataContext();


            var people = (from p in db.Persons
                          where p.NeedsUpload == true
                          select p);

            if (people.Count() > 0)
            {
                try
                {
                    S2API api = new S2API(_s2URI, _s2RSMAccount, _s2RSMPassword);
                    foreach (Person p in people)
                    {
                        if (api.SavePerson(p))
                        {
                            p.NeedsUpload = false;
                        }
                    }
                    api.LogOut();
                }
                catch (Exception e)
                {
                    WriteToEventLogError("Exception thrown uploading people: " + e.ToString());
                }
                db.SubmitChanges();
            }
        }
예제 #12
0
        public ActionResult Reports(FormCollection collection)
        {
            MemoryStream            memStream = new MemoryStream(100);
            TextWriter              tw        = new StreamWriter(memStream);
            RSMDataModelDataContext context   = new RSMDataModelDataContext();


            switch (collection["ReportName"])
            {
            case "1":
                tw.WriteLine("Access Level Name,Access Level Description,People");
                foreach (AccessLevelReport alRpt in context.AccessLevelReports.OrderBy("AccessLevelName"))
                {
                    tw.WriteLine(String.Format("{0},\"{1}\",\"{2}\"", alRpt.AccessLevelName, alRpt.AccessLevelDesc, alRpt.people));
                }
                memStream.Seek(0, SeekOrigin.Begin);
                return(File(memStream, "text/csv", "Access Level Report.csv"));

            case "2":
                tw.WriteLine("Last Name, First Name, Department, Position, Levels");
                foreach (EmpAccessLevelReport elRpt in context.EmpAccessLevelReports.OrderBy("lastname"))
                {
                    tw.WriteLine(String.Format("{1},{0},\"{2}\",{3},\"{4}\"", elRpt.firstname, elRpt.lastname, elRpt.Deptdescr, elRpt.jobdescr, elRpt.levels));
                }
                memStream.Seek(0, SeekOrigin.Begin);
                return(File(memStream, "text/csv", "Employee Access Report.csv"));
            }
            ;

            return(RedirectToAction("Reports"));
        }
예제 #13
0
        public S2API(string uri, string user, string password, bool encryptedPassword = true)
        {
            _uri = uri;
            var crypt = new QuickAES();

            try
            {
                if (!Login(user, password, encryptedPassword))
                {
                    throw (new Exception(string.Format("Failed to log into S2 at {2} as {0} with the password {1}", user,
                                                       crypt.DecryptString(password), uri)));
                }
            }
            catch (Exception e)
            {
                throw (new Exception(string.Format("Failed to log into S2 at {2} as {0} with the password {1}\n{3}", user,
                                                   crypt.DecryptString(password), uri, e)));
            }

            using (var context = new RSMDataModelDataContext())
            {
                ImportSystem = context.ExternalSystems.FirstOrDefault(x => x.Name == "S2 Import");
                ExportSystem = context.ExternalSystems.FirstOrDefault(x => x.Name == "S2 Export");
            }

            ApiVersion = GetAPIVersion();
        }
예제 #14
0
        public ActionResult AssignedLevels(int id)
        {
            if (id == 0)
            {
                return(Json(""));
            }

            var  context = new RSMDataModelDataContext();
            Role role    = (from p in context.Roles
                            where p.RoleID == id
                            select p).First();


            var jsonAssLevels = new
            {
                total   = 1,
                page    = 1,
                records = role.AccessLevelRoles.Count,
                rows    = (
                    from l in role.AccessLevelRoles
                    select new
                {
                    i = l.AccessLevelID,
                    cell = new string[] {
                        l.AccessLevelID.ToString(), l.AccessLevel.AccessLevelName.ToString(), l.AccessLevel.AccessLevelDesc.ToString()
                    }
                }).ToArray()
            };

            return(Json(jsonAssLevels));
        }
예제 #15
0
        public ActionResult EventDetails(int ID, int?Filter)
        {
            ViewBag.IsAdmin = false;
            if (Filter.HasValue)
            {
                ViewBag.Filter = Filter;
            }
            else
            {
                ViewBag.Filter = -1;
            }


            ViewBag.IsAdmin = true;

            RSMDataModelDataContext context = new RSMDataModelDataContext();

            try
            {
                var entry = (from e in context.LogEntries
                             where e.ID == ID
                             select e).Single();


                return(View(entry));
            }
            catch (Exception)
            {
                return(RedirectToAction("ActivityLog", new { filter = Filter }));
            }
        }
예제 #16
0
        public ActionResult Clone(int id)
        {
            RSMDataModelDataContext context = new RSMDataModelDataContext();

            JCLRoleRule source = (from j in context.JCLRoleRules
                                  where j.ID == id
                                  select j).Single();

            JCLRoleRule dest = new JCLRoleRule();
            JCLRole     newRole;

            dest.JobCode  = source.JobCode;
            dest.DeptID   = source.DeptID;
            dest.Location = source.Location;

            context.JCLRoleRules.InsertOnSubmit(dest);
            context.SubmitChanges();


            foreach (JCLRole role in source.JCLRoles)
            {
                newRole             = new JCLRole();
                newRole.RoleID      = role.RoleID;
                newRole.JCLRoleRule = dest;
                context.JCLRoles.InsertOnSubmit(newRole);
            }

            context.SubmitChanges();

            return(RedirectToAction("Edit", new { id = dest.ID, message = "You are now editing a new copy of your previous rule." }));
        }
예제 #17
0
        public ActionResult JobCode(string id, FormCollection collection)
        {
            RSMDataModelDataContext context = new RSMDataModelDataContext();

            try
            {
                var model = (from e in context.Jobs
                             where e.JobCode == id
                             select e).Single();
                model.DisplayDescription = collection["DisplayDescription"];
                model.Credentials        = collection["Credentials"];

                var people = (from p in context.Persons where p.JobCode == id select p).ToArray();

                foreach (var p in people)
                {
                    p.NeedsUpload = true;
                }

                context.SubmitChanges();
            }
            catch (Exception)
            {
                return(RedirectToAction("JobCode", new { id = id }));
            }

            return(RedirectToAction("JobCodes"));
        }
예제 #18
0
        public override bool IsUserInRole(string username, string rolename)
        {
            var context = new RSMDataModelDataContext();

            try
            {
                var person = context.Persons.FirstOrDefault(
                    x => x.username.Equals(username, StringComparison.InvariantCultureIgnoreCase));

                if (person == null)
                {
                    return(false);
                }

                if (rolename.Equals("admin", StringComparison.InvariantCultureIgnoreCase))
                {
                    return(person.IsAdmin);
                }

                return(true);
            }
            catch (Exception)
            {
                if (username.Equals("admin", StringComparison.InvariantCultureIgnoreCase))
                {
                    return(true);
                }

                return(false);
            }
        }
예제 #19
0
        public static void Delete <T>(RSMDataModelDataContext context, List <T> entityCollection) where T : class, IEntity
        {
            if (context == null)
            {
                return;
            }
            if (entityCollection == null)
            {
                return;
            }
            if (!entityCollection.Any())
            {
                return;
            }

            var dataSet = context.GetTable <T>();

            foreach (var entity in entityCollection)
            {
                var deleted = context.GetTable <T>().FirstOrDefault(x => x.Id.Equals(entity.Id));
                if (deleted == null)
                {
                    continue;
                }

                dataSet.DeleteOnSubmit(deleted);
            }
        }
예제 #20
0
        public void Search()
        {
            const string settingName = "Test Setting";

            var system  = Factory.CreateExternalSystem(BaseId + 1, "Test System", ExternalSystemDirection.None);
            var system2 = Factory.CreateExternalSystem(BaseId + 2, "Test System 2", ExternalSystemDirection.None);

            var testSetting  = Factory.CreateSetting(BaseId + 1, settingName, "Test Setting Label", "value", 0, true, InputTypes.Text, system);
            var testSetting2 = Factory.CreateSetting(BaseId + 2, settingName + " 2", "Test Setting Label 2", "value", 0, true, InputTypes.Text, system2);
            var testSetting3 = Factory.CreateSetting(BaseId + 3, settingName + " 2", "Test Setting Label 2", "value", 0, true, InputTypes.Text, system);

            using (var context = new RSMDataModelDataContext())
            {
                context.ExternalSystems.InsertOnSubmit(system);
                context.ExternalSystems.InsertOnSubmit(system2);

                context.Settings.InsertOnSubmit(testSetting);
                context.Settings.InsertOnSubmit(testSetting2);
                context.Settings.InsertOnSubmit(testSetting3);

                context.SubmitChanges();
            }

            var controller = new Library.Controllers.Settings();

            var results = controller.Search(o => o.SystemId == system.Id);

            Assert.IsNotNull(results, "Missing results");
            Assert.IsTrue(results.Succeeded, "Call Failed");
            Assert.IsNotNull(results.Entity, "Missing entity");
            Assert.AreEqual(results.Entity.Count, 2, "Incorrect row count returned");
        }
예제 #21
0
        ActionResult DisplayOrReview(int ID, ReviewModes reviewMode, string returnView, string thisView)
        {
            UpdateLastAccess();
            var    context = new RSMDataModelDataContext();
            Person person  = (from p in context.Persons
                              where p.PersonID == ID
                              select p).Single();

            string s2Host = ConfigurationManager.AppSettings["S2Address"];

            try
            {
                UpdateLastAccess();
            }
            catch (Exception)
            {
                // Failure to update last access should not be an show stopper
            }

            try
            {
                XmlNode nd        = API.GetPicture(person.PersonID.ToString());
                string  fileName  = string.Format("~/Content/Images/employees/{0}", nd["PICTUREURL"].InnerText);
                byte[]  imageData = Convert.FromBase64String(nd["PICTURE"].InnerText);

                string filePath = Server.MapPath(Url.Content(fileName));

                using (FileStream stream = new FileStream(filePath, FileMode.Create))
                {
                    using (BinaryWriter writer = new BinaryWriter(stream))
                    {
                        writer.Write(imageData);
                        writer.Close();
                    }
                }

                ViewBag.PicURL = Url.Content(fileName);
            }
            catch (Exception)
            {
                string userImage = string.Format("~/Content/images/employees/missing.jpg", ID);
                ViewBag.PicURL = Url.Content(userImage);
            }

            ViewBag.AssRolesURL = Url.Action("AssignedRoles", new { ID = person.PersonID });
            ViewBag.IsAdmin     = false;
            ViewBag.ReviewMode  = reviewMode;
            ViewBag.ReturnView  = returnView;
            if (User.IsInRole("admin") || User.Identity.Name == "admin")
            {
                ViewBag.IsAdmin = true;
            }

            ViewBag.IsReview = (reviewMode != ReviewModes.NONE);

            ViewBag.BackView = thisView;

            return(View("Details", person));
        }
예제 #22
0
        ActionResult Edit(int ID, bool fromReview, string back)
        {
            string s2Host  = ConfigurationManager.AppSettings["S2Address"];
            var    context = new RSMDataModelDataContext();
            Person person  = (from p in context.Persons
                              where p.PersonID == ID
                              select p).First();

            try
            {
                UpdateLastAccess();
            }
            catch (Exception)
            {
                // Failure to update last access should not be a show stopper
            }

            try
            {
                //S2API api = new S2API(String.Format("{0}/goforms/nbapi", s2Host));
                XmlNode nd        = API.GetPicture(person.PersonID.ToString());
                string  fileName  = string.Format("~/Content/Images/employees/{0}", nd["PICTUREURL"].InnerText);
                byte[]  imageData = Convert.FromBase64String(nd["PICTURE"].InnerText);

                string filePath = Server.MapPath(Url.Content(fileName));

                using (FileStream stream = new FileStream(filePath, FileMode.Create))
                {
                    using (BinaryWriter writer = new BinaryWriter(stream))
                    {
                        writer.Write(imageData);
                        writer.Close();
                    }
                }

                ViewBag.PicURL = Url.Content(fileName);
            }
            catch (Exception)
            {
                string userImage = string.Format("~/Content/images/employees/missing.jpg", ID);
                ViewBag.PicURL = Url.Content(userImage);
            }



            ViewBag.AvailRolesURL = Url.Action("AvailableRoles", new { ID = person.PersonID });
            ViewBag.AssRolesURL   = Url.Action("AssignedRoles", new { ID = person.PersonID });
            ViewBag.IsAdmin       = false;
            if (User.IsInRole("admin") || User.Identity.Name == "admin")
            {
                ViewBag.IsAdmin = true;
            }

            ViewBag.BackView = back;
            ViewBag.IsReview = fromReview;
            return(View("Edit", person));
        }
예제 #23
0
        public Settings(RSMDataModelDataContext context)
            : base(context)
        {
            DbContext.DeferredLoadingEnabled = false;
            var loadOptions = new DataLoadOptions();

            loadOptions.LoadWith <Setting>(t => t.ExternalSystem);
            DbContext.LoadOptions = loadOptions;
        }
예제 #24
0
 public void TestCleanup()
 {
     using (var context = new RSMDataModelDataContext())
     {
         context.Settings.DeleteAllOnSubmit(context.Settings.Where(x => x.Id >= BaseId));
         context.ExternalSystems.DeleteAllOnSubmit(context.ExternalSystems.Where(x => x.Id >= BaseId));
         context.SubmitChanges();
     }
 }
예제 #25
0
        private void button10_Click(object sender, EventArgs e)
        {
            var    ID      = 2;
            var    context = new RSMDataModelDataContext();
            Person person  = (from p in context.Persons
                              where p.PersonID == ID
                              select p).Single();

            txtOutput.Text = person.DisplayCredentials;
        }
예제 #26
0
        private void button10_Click(object sender, EventArgs e)
        {
            var ID      = 2;
            var context = new RSMDataModelDataContext();
            var person  = (from p in context.Persons
                           where p.PersonID == ID
                           select p).Single();

            AssignView(person.DisplayCredentials, null);
        }
예제 #27
0
        private void ExportAll()
        {
            S2API api = new S2API("http://64.129.189.200/goforms/nbapi", "admin", "admin");
            RSMDataModelDataContext db = new RSMDataModelDataContext();

            foreach (Person person in db.Persons)
            {
                api.SavePerson(person);
            }
            txtOutput.Text = "Done exporting";
        }
예제 #28
0
        public ActionResult SysLog(int filter, string sidx, string sord, int page, int rows)
        {
            var context      = new RSMDataModelDataContext();
            int pageIndex    = Convert.ToInt32(page) - 1;
            int pageSize     = rows;
            int totalRecords = context.LogEntries.Count();
            int totalPages   = (int)Math.Ceiling((float)totalRecords / (float)pageSize);


            List <LogEntry> entries;


            if (filter >= 0)
            {
                entries = (from e in context.LogEntries
                           where e.Source == filter
                           select e).OrderBy("EventDate " + sord)
                          .Skip(pageIndex * pageSize)
                          .Take(pageSize).ToList();
            }
            else
            {
                entries = context.LogEntries
                          .OrderBy("EventDate " + sord)
                          .Skip(pageIndex * pageSize)
                          .Take(pageSize).ToList();
            }

            // colNames: ['Status', 'Name', 'BadgeNumber', 'Department', 'Job', 'Facility', 'LastUpdated'],
            var jsonData = new
            {
                total   = totalPages,
                page    = page,
                records = totalRecords,
                rows    = (
                    from entry in entries
                    select new
                {
                    i = entry.ID,
                    cell = new string[] {
                        entry.ID.ToString(),
                        ((int)entry.Severity).ToString(),
                        entry.EventDate.ToString(),
                        entry.SourceName,
                        entry.Message
                    }
                }).ToArray()
            };

            return(Json(jsonData));
        }
예제 #29
0
        private void ExportAll()
        {
            var api = new S2API(S2APIUrl, S2APIUser, S2APIPassword, false);

            using (var db = new RSMDataModelDataContext())
            {
                foreach (var person in db.Persons)
                {
                    api.SavePerson(person);
                }
            }

            txtOutput.Text = "Done exporting";
        }
예제 #30
0
        public ActionResult Details(int id)
        {
            var  context = new RSMDataModelDataContext();
            Role role    = (from p in context.Roles
                            where p.RoleID == id
                            select p).First();

            ViewBag.IsAdmin      = false;
            ViewBag.AssLevelsURL = Url.Action("AssignedLevels", new { ID = role.RoleID });
            ViewBag.Role         = role;
            if (User.IsInRole("admin") || User.Identity.Name == "admin")
            {
                ViewBag.IsAdmin = true;
            }
            return(View(role));
        }