Beispiel #1
0
        public static string AddGroup(string gname, string currentuseruid)
        {
            string Output = string.Empty;

            try
            {
                // open access dynamic databse configuration
                string SiteUrl = HttpContext.Current.Request.UrlReferrer.Scheme + "://" +
                                 HttpContext.Current.Request.UrlReferrer.Host + ":" +
                                 HttpContext.Current.Request.UrlReferrer.Port + "/" +
                                 HttpContext.Current.Request.UrlReferrer.Segments[1];
                if (MyUtilities.DevelopMode)
                {
                    SiteUrl = MyUtilities.ProjectServerInstanceURL(SPContext.Current);
                }

                MyUtilities.ModifyConnectionString(SiteUrl);

                using (IObjectScope scope = ObjectScopeProvider1.GetNewObjectScope())
                {
                    List <Groups> groups = (from c in scope.GetOqlQuery <Users>().ExecuteEnumerable()
                                            from d in c.groups
                                            where c.ResourceUID.Equals(currentuseruid) && d.name.Equals(gname)
                                            select d).ToList();
                    if (groups.Count == 0)
                    {
                        List <Users> userses = (from c in scope.GetOqlQuery <Users>().ExecuteEnumerable()
                                                where c.ResourceUID.Equals(currentuseruid)
                                                select c).ToList();
                        if (userses.Count > 0)
                        {
                            scope.Transaction.Begin();
                            var new_group = new Groups();
                            new_group.name = gname;
                            new_group.UID  = Guid.NewGuid().ToString();
                            userses[0].groups.Add(new_group);
                            scope.Add(userses[0]);
                            scope.Transaction.Commit();
                            Output = new_group.UID;
                        }
                    }
                    else
                    {
                        Output = groups[0].UID;
                    }
                }
            }
            catch (Exception)
            {
                // Error log here
            }
            return(Output);
        }
Beispiel #2
0
        /// <summary>
        /// Get a collection of profiles based upon a user name matching string and inactivity date.
        /// </summary>
        /// <param name="authenticationOption">Current authentication option setting.</param>
        /// <param name="userNameToMatch">Characters representing user name to match (L to R).</param>
        /// <param name="userInactiveSinceDate">Inactivity date for deletion.</param>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <param name="totalRecords">Total records found (output).</param>
        /// <returns>Collection of profiles.</returns>
        public override System.Web.Profile.ProfileInfoCollection FindInactiveProfilesByUserName(System.Web.Profile.ProfileAuthenticationOption authenticationOption, string userNameToMatch, DateTime userInactiveSinceDate, int pageIndex, int pageSize, out int totalRecords)
        {
            IObjectScope objScope = ORM.GetNewObjectScope();
            const string queryInactiveProfilesByUserName =
                @"SELECT * FROM EmployeeProfileExtent AS o WHERE o.Employee.Name LIKE $1 AND o.Employee.LastActivityDate <= $2";
            ProfileInfoCollection pic = new ProfileInfoCollection();
            IQuery query = objScope.GetOqlQuery(queryInactiveProfilesByUserName);

            using (IQueryResult result = query.Execute(userNameToMatch + '*', userInactiveSinceDate))
            {
                totalRecords = result.Count;
                int counter    = 0;
                int startIndex = pageSize * pageIndex;
                int endIndex   = startIndex + pageSize - 1;

                foreach (object res in result)
                {
                    if (counter >= startIndex)
                    {
                        EmployeeProfile ep = res as EmployeeProfile;
                        pic.Add(new ProfileInfo(ep.Employee.Name, false, ep.Employee.LastActivityDate, ep.LastUpdatedDate, 0));
                    }
                    if (counter >= endIndex)
                    {
                        break;
                    }
                    counter += 1;
                }
            }
            return(pic);
        }
Beispiel #3
0
        public static bool ModifyGroup(object details)
        {
            // first row in details contains current userid
            bool Output = false;

            try
            {
                var top_array = (Array)details;
                if (top_array.Length > 0)
                {
                    // open access dynamic databse configuration
                    string SiteUrl = HttpContext.Current.Request.UrlReferrer.Scheme + "://" +
                                     HttpContext.Current.Request.UrlReferrer.Host + ":" +
                                     HttpContext.Current.Request.UrlReferrer.Port + "/" +
                                     HttpContext.Current.Request.UrlReferrer.Segments[1];
                    if (MyUtilities.DevelopMode)
                    {
                        SiteUrl = MyUtilities.ProjectServerInstanceURL(SPContext.Current);
                    }

                    MyUtilities.ErrorLog(SiteUrl, EventLogEntryType.Error);

                    MyUtilities.ModifyConnectionString(SiteUrl);

                    using (IObjectScope scope = ObjectScopeProvider1.GetNewObjectScope())
                    {
                        var    array          = (Array)top_array.GetValue(0);
                        string currentuseruid = array.GetValue(0).ToString();
                        for (var index = 1; index < top_array.Length; index++)
                        {
                            array = (Array)top_array.GetValue(index);
                            if (array.Length > 0)
                            {
                                string        groupuid  = array.GetValue(0).ToString();
                                string        groupname = array.GetValue(1).ToString();
                                List <Groups> groupses  = (from c in scope.GetOqlQuery <Users>().ExecuteEnumerable()
                                                           from d in c.groups
                                                           where c.ResourceUID.Equals(currentuseruid) && d.UID.Equals(groupuid)
                                                           select d).ToList();
                                if (groupses.Count > 0)
                                {
                                    scope.Transaction.Begin();
                                    groupses[0].name = groupname;
                                    scope.Add(groupses[0]);
                                    scope.Transaction.Commit();
                                }
                            }
                        }
                    }
                }
                Output = true;
            }
            catch (Exception)
            {
                // error log goes here
            }
            return(Output);
        }
Beispiel #4
0
        /// <summary>
        /// Get the number of inactive profiles based upon an inactivity date.
        /// </summary>
        /// <param name="authenticationOption">Current authentication option setting.</param>
        /// <param name="userInactiveSinceDate">Inactivity date for deletion.</param>
        /// <returns>Number of profiles.</returns>
        public override int GetNumberOfInactiveProfiles(System.Web.Profile.ProfileAuthenticationOption authenticationOption, DateTime userInactiveSinceDate)
        {
            IObjectScope objScope       = ORM.GetNewObjectScope();
            const string queryOnlineNum = @"ELEMENT (SELECT COUNT(*) FROM EmployeeProfileExtent AS o WHERE o.Employee.LastActivityDate > $1)";
            TimeSpan     onlineSpan     = new TimeSpan(0, System.Web.Security.Membership.UserIsOnlineTimeWindow, 0);
            DateTime     compareTime    = DateTime.Now.Subtract(onlineSpan);
            IQuery       oqlQuery       = objScope.GetOqlQuery(queryOnlineNum);

            using (IQueryResult result = oqlQuery.Execute(compareTime))
                return((int)result[0]);
        }
Beispiel #5
0
        public override string[] GetAllRoles()
        {
            IObjectScope objScope      = ORM.GetNewObjectScope();
            const string queryAllRoles = @"SELECT o.Name FROM RoleExtent AS o";

            using (IQueryResult result = objScope.GetOqlQuery(queryAllRoles).Execute())
            {
                string[] roles = new string[result.Count];
                result.CopyTo(roles, 0);
                return(roles);
            }
        }
Beispiel #6
0
        /// <summary>
        /// Gets a list of the roles that a specified user is in for the
        /// configured <see cref="ApplicationName"/>.
        /// </summary>
        /// <remarks>
        /// This method is called by the ASP.NET runtime when using
        /// UrlAuthorizationModule (the <c>authorization</c> element of web.config)
        /// to secure your website, or when calling IsInRole() on the current
        /// IPrincipal (ex: Page.User.IsInRole("Admin"))
        /// </remarks>
        /// <param name="username">The user to return a list of roles for.</param>
        /// <returns>A string array containing the names of all the roles that the
        /// specified user is in for the configured <see cref="ApplicationName"/>
        /// </returns>
        public override string[] GetRolesForUser(string username)
        {
            IObjectScope objScope          = ORM.GetNewObjectScope();
            const string queryRolesForUser =
                @"SELECT o.Name FROM RoleExtent AS o, o.Employees AS e WHERE e.Name = $1";

            using (IQueryResult result = objScope.GetOqlQuery(queryRolesForUser).Execute(username))
            {
                string[] roles = new string[result.Count];
                result.CopyTo(roles, 0);
                return(roles);
            }
        }
Beispiel #7
0
        /// <summary>
        /// Gets the number of users currently on-line.
        /// </summary>
        /// <returns>  /// # of users on-line.</returns>
        public override int GetNumberOfUsersOnline()
        {
            const string queryOnlineNum = @"ELEMENT (SELECT COUNT(*) FROM EmployeeExtent AS o WHERE o.LastActivityDate > $1)";
            TimeSpan     onlineSpan     = new TimeSpan(0, System.Web.Security.Membership.UserIsOnlineTimeWindow, 0);
            DateTime     compareTime    = DateTime.Now.Subtract(onlineSpan);

            IObjectScope objScope = ORM.GetNewObjectScope();
            IQuery       oqlQuery = objScope.GetOqlQuery(queryOnlineNum);

            using (IQueryResult result = oqlQuery.Execute(compareTime))
            {
                return((int)result[0]);
            }
        }
Beispiel #8
0
        private Employee ResolveEmployeeByName(IObjectScope objScope, string name)
        {
            Employee     e = null;
            const string queryEmployeeByName = "ELEMENT (SELECT o FROM EmployeeExtent AS o WHERE o.Name = $1)";
            IQuery       oqlQuery            = objScope.GetOqlQuery(queryEmployeeByName);

            using (IQueryResult result = oqlQuery.Execute(name))
            {
                if (result.Count > 0)
                {
                    e = result[0] as Employee;
                }
            }
            return(e);
        }
Beispiel #9
0
        public override bool IsUserInRole(string username, string roleName)
        {
            IObjectScope objScope             = ORM.GetNewObjectScope();
            const string queryUserInRoleExist =
                @"SELECT o.Name FROM RoleExtent AS o WHERE EXISTS e IN o.Employees : (e.Name = $1) AND o.Name = $2";

            using (IQueryResult result = objScope.GetOqlQuery(queryUserInRoleExist).Execute(username, roleName))
            {
                if (result.Count > 0)
                {
                    return(true);
                }
                return(false);
            }
        }
Beispiel #10
0
        private bool Checkauthorization(IObjectScope scope, string username)
        {
            List <User> users = (from c in scope.GetOqlQuery <User>().ExecuteEnumerable()
                                 where c.Username.ToLower().Equals(username.ToLower())
                                 select c).ToList();

            if (users.Count > 0 && users[0].IsheAdmin)
            {
                ViewData["IsheAdmin"]            = users[0].IsheAdmin;
                ViewData["IsheDonationReceiver"] = users[0].IsheDonationReceiver;
                return(true);
            }
            ViewData["IsheAdmin"]            = false;
            ViewData["IsheDonationReceiver"] = false;
            return(false);
        }
Beispiel #11
0
        private EmployeeProfile ResolveEmployeeProfileByName(IObjectScope objScope, string userName)
        {
            if (null == userName)
            {
                return(null);
            }
            EmployeeProfile ep = null;
            const string    queryEmployeeProfile =
                @"ELEMENT (SELECT * FROM EmployeeProfileExtent AS o WHERE o.Employee.Name = $1)";
            IQuery oqlQuery = objScope.GetOqlQuery(queryEmployeeProfile);

            using (IQueryResult result = oqlQuery.Execute(userName))
                if (result.Count > 0)
                {
                    ep = result[0] as EmployeeProfile;
                }
            return(ep);
        }
Beispiel #12
0
        public static string GetProjects(string groupuid, string currentuseruid)
        {
            var outputTable = new DataTable();

            outputTable.Columns.Add("uid");
            outputTable.Columns.Add("name");
            try
            {
                // open access dynamic databse configuration
                string SiteUrl = HttpContext.Current.Request.UrlReferrer.Scheme + "://" +
                                 HttpContext.Current.Request.UrlReferrer.Host + ":" +
                                 HttpContext.Current.Request.UrlReferrer.Port + "/" +
                                 HttpContext.Current.Request.UrlReferrer.Segments[1];
                if (MyUtilities.DevelopMode)
                {
                    SiteUrl = MyUtilities.ProjectServerInstanceURL(SPContext.Current);
                }

                MyUtilities.ModifyConnectionString(SiteUrl);

                using (IObjectScope scope = ObjectScopeProvider1.GetNewObjectScope())
                {
                    List <Groups> groups = (from c in scope.GetOqlQuery <Users>().ExecuteEnumerable()
                                            from d in c.groups
                                            where c.ResourceUID.Equals(currentuseruid) && d.UID.Equals(groupuid)
                                            select d).ToList();
                    if (groups.Count > 0)
                    {
                        foreach (var project in groups[0].projects)
                        {
                            var testrow = outputTable.NewRow();
                            testrow["uid"]  = project.uid;
                            testrow["name"] = project.name;
                            outputTable.Rows.Add(testrow);
                        }
                    }
                }
            }
            catch (Exception)
            {
                // error log here
            }
            return(MyUtilities.Serialize(outputTable));
        }
Beispiel #13
0
        private Role ResolveRoleByName(IObjectScope objScope, string roleName)
        {
            if (null == roleName)
            {
                return(null);
            }
            Role         r         = null;
            const string queryRole = @"ELEMENT (SELECT * FROM RoleExtent AS o WHERE o.Name = $1)";
            IQuery       oqlQuery  = objScope.GetOqlQuery(queryRole);

            using (IQueryResult result = oqlQuery.Execute(roleName))
            {
                if (result.Count > 0)
                {
                    r = result[0] as Role;
                }
            }
            return(r);
        }
Beispiel #14
0
        public override string GetUserNameByEmail(string email)
        {
            const string queryEmployeeNameByEmail =
                @"ELEMENT (SELECT o.Name FROM EmployeeExtent AS o WHERE o.Email = $1)";
            IObjectScope objScope = ORM.GetNewObjectScope();
            IQuery       oqlQuery = objScope.GetOqlQuery(queryEmployeeNameByEmail);

            using (IQueryResult result = oqlQuery.Execute(email))
            {
                if (result.Count > 0)
                {
                    return(result[0].ToString());
                }
                else
                {
                    return(String.Empty);
                }
            }
        }
Beispiel #15
0
        private Employee ResolveEmployeeByName(IObjectScope objScope, string name)
        {
            Employee     e = null;
            const string queryEmployeeByName =
                @"ELEMENT (SELECT o FROM EmployeeExtent AS o WHERE o.Name = $1 AND o.IsApproved = true AND o.isLockedOut = false)";
            IQuery oqlQuery = objScope.GetOqlQuery(queryEmployeeByName);

            using (IQueryResult result = oqlQuery.Execute(name))
            {
                if (result.Count > 0)
                {
                    e = result[0] as Employee;
                }
                else
                {
                    throw new ProviderException(string.Format(MSG.ProfileProvider_Employee_Not_Exist, name));
                }
            }
            return(e);
        }
Beispiel #16
0
        public override string[] FindUsersInRole(string roleName, string usernameToMatch)
        {
            IObjectScope objScope = ORM.GetNewObjectScope();
            Role         role     = ResolveRoleByName(objScope, roleName);

            if (null == role)
            {
                throw new ProviderException(String.Format("Role: {0} is not exist", roleName));
            }

            const string queryFindUsersInRole =
                @"SELECT o.Name FROM EmployeeExtent AS o WHERE EXISTS r IN o.Roles : (r = $1) AND o.Name like $2";

            using (IQueryResult result = objScope.GetOqlQuery(queryFindUsersInRole).Execute(role, usernameToMatch + '*'))
            {
                string[] users = new string[result.Count];
                result.CopyTo(users, 0);
                return(users);
            }
        }
Beispiel #17
0
        /// <summary>
        /// Deletes profiles that have been inactive since the specified date.
        /// </summary>
        /// <param name="authenticationOption">Current authentication option setting.</param>
        /// <param name="userInactiveSinceDate">Inactivity date for deletion.</param>
        /// <returns>Number of records deleted.</returns>
        public override int DeleteInactiveProfiles(System.Web.Profile.ProfileAuthenticationOption authenticationOption, DateTime userInactiveSinceDate)
        {
            IObjectScope objScope = ORM.GetNewObjectScope();

            objScope.Transaction.Begin();

            int          deleteCounter         = 0;
            const string queryInactiveProfiles =
                @"SELECT * FROM EmployeeProfileExtent AS o WHERE o.Employee.LastActivityDate <= $1";
            IQuery oqlQuery = objScope.GetOqlQuery(queryInactiveProfiles);

            using (IQueryResult result = oqlQuery.Execute(userInactiveSinceDate))
            {
                foreach (object p in result)
                {
                    objScope.Remove(p);
                    deleteCounter++;
                }
            }
            objScope.Transaction.Commit();
            return(deleteCounter);
        }
Beispiel #18
0
        private ProfileInfoCollection QueryProfileInfos(IObjectScope objScope, string oqlQuery, object oqlValue, int pageIndex, int pageSize, out int totalRecords)
        {
            ProfileInfoCollection pic = new ProfileInfoCollection();
            IQuery query = objScope.GetOqlQuery(oqlQuery);

            IQueryResult result;

            if (oqlValue != null)
            {
                result = query.Execute(oqlValue);
            }
            else
            {
                result = query.Execute();
            }

            using (result)
            {
                totalRecords = result.Count;
                int counter    = 0;
                int startIndex = pageSize * pageIndex;
                int endIndex   = startIndex + pageSize - 1;

                foreach (object res in result)
                {
                    if (counter >= startIndex)
                    {
                        EmployeeProfile ep = res as EmployeeProfile;
                        pic.Add(new ProfileInfo(ep.Employee.Name, false, ep.Employee.LastActivityDate, ep.LastUpdatedDate, 0));
                    }
                    if (counter >= endIndex)
                    {
                        break;
                    }
                    counter += 1;
                }
            }
            return(pic);
        }
Beispiel #19
0
        private MembershipUserCollection QueryMembershipUsers(IObjectScope objScope, string oqlQuery, string likeValue, int pageIndex, int pageSize, out int totalRecords)
        {
            MembershipUserCollection users = new MembershipUserCollection();
            IQuery       query             = objScope.GetOqlQuery(oqlQuery);
            IQueryResult result;

            if (likeValue != null)
            {
                result = query.Execute(likeValue + '*'); // OQL use * as wildcard instead of %
            }
            else
            {
                result = query.Execute();
            }

            using (result)
            {
                totalRecords = result.Count;
                int counter    = 0;
                int startIndex = pageSize * pageIndex;
                int endIndex   = startIndex + pageSize - 1;

                foreach (object res in result)
                {
                    if (counter >= startIndex)
                    {
                        Employee e = res as Employee;
                        users.Add(GetUserFromEmployee(e));
                    }
                    if (counter >= endIndex)
                    {
                        break;
                    }
                    counter += 1;
                }
            }
            return(users);
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            // Browser detection and redirecting to error page
            if (Request.Browser.Browser.ToLower() == "ie" && Convert.ToDouble(Request.Browser.Version) < 7)
            {
                SPUtility.TransferToErrorPage("To view this report use later versions of IE 6.0");
            }
            else
            {
                try
                {
                    string SiteUrl = MyUtilities.ProjectServerInstanceURL(SPContext.Current);

                    var Resource_Svc = new Resource();
                    var Project_Svc  = new Project();

                    Resource_Svc.UseDefaultCredentials = true;
                    Project_Svc.UseDefaultCredentials  = true;

                    Resource_Svc.Url = SiteUrl + "/_vti_bin/psi/resource.asmx";
                    Project_Svc.Url  = SiteUrl + "/_vti_bin/psi/project.asmx";

                    Resource_Svc.AllowAutoRedirect = true;
                    Project_Svc.AllowAutoRedirect  = true;

                    if (MyUtilities.IndividualPages)
                    {
                        LnkConfigButton.PostBackUrl = SiteUrl + "/_layouts/ITXProjectGovernanceReport/ITXPGReport.aspx";
                    }
                    else
                    {
                        LnkConfigButton.Visible = false;
                    }

                    // setting current user uid
                    LblCurUserUId.Text = Resource_Svc.GetCurrentUserUid().ToString();

                    // For Group Repeater control

                    var GroupTable = new DataTable();
                    GroupTable.Columns.Add("title");
                    GroupTable.Columns.Add("grpid");

                    // impersonation here
                    try
                    {
                        var wik = WindowsIdentity.Impersonate(IntPtr.Zero);
                    }
                    catch (Exception)
                    {
                    }

                    MyUtilities.ModifyConnectionString(SiteUrl);

                    using (IObjectScope scope = ObjectScopeProvider1.GetNewObjectScope())
                    {
                        // creating the user account into db if not exists
                        List <Users> userses = (from c in scope.GetOqlQuery <Users>().ExecuteEnumerable()
                                                where c.ResourceUID.Equals(LblCurUserUId.Text)
                                                select c).ToList();
                        if (userses.Count == 0)
                        {
                            scope.Transaction.Begin();
                            var new_user = new Users();
                            new_user.ResourceUID = LblCurUserUId.Text;
                            scope.Add(new_user);
                            scope.Transaction.Commit();

                            userses = (from c in scope.GetOqlQuery <Users>().ExecuteEnumerable()
                                       where c.ResourceUID.Equals(LblCurUserUId.Text)
                                       select c).ToList();
                        }

                        List <Groups> groups = (from c in scope.GetOqlQuery <Users>().ExecuteEnumerable()
                                                from d in c.groups
                                                where
                                                c.ResourceUID.Equals(LblCurUserUId.Text) &&
                                                !d.UID.Equals(Guid.Empty.ToString())
                                                select d).ToList();
                        foreach (var group in groups)
                        {
                            var new_row = GroupTable.NewRow();
                            new_row["title"] = group.name;
                            new_row["grpid"] = group.UID;
                            GroupTable.Rows.Add(new_row);
                        }

                        RptrGroupnames.DataSource = GroupTable;
                        RptrGroupnames.DataBind();

                        // For Project name Repeater Control
                        var ProjectTable = MyUtilities.GetProjects_DataTable(SiteUrl, new Guid(LblCurUserUId.Text));

                        groups = (from c in scope.GetOqlQuery <Users>().ExecuteEnumerable()
                                  from d in c.groups
                                  where c.ResourceUID.Equals(LblCurUserUId.Text) && d.UID.Equals(Guid.Empty.ToString())
                                  select d).ToList();

                        if (groups.Count == 0)
                        {
                            if (userses.Count > 0)
                            {
                                scope.Transaction.Begin();
                                var new_group = new Groups();
                                new_group.name = "Not Grouped.";
                                new_group.UID  = Guid.Empty.ToString();
                                userses[0].groups.Add(new_group);
                                scope.Add(userses[0]);
                                scope.Transaction.Commit();
                            }
                            groups = (from c in scope.GetOqlQuery <Users>().ExecuteEnumerable()
                                      from d in c.groups
                                      where
                                      c.ResourceUID.Equals(LblCurUserUId.Text) &&
                                      d.UID.Equals(Guid.Empty.ToString())
                                      select d).ToList();
                        }

                        // Checking and adding missed projects to the user
                        foreach (DataRow row in ProjectTable.Rows)
                        {
                            var count = (from c in scope.GetOqlQuery <Users>().ExecuteEnumerable()
                                         from d in c.groups
                                         from f in d.projects
                                         where
                                         c.ResourceUID.Equals(LblCurUserUId.Text) &&
                                         f.uid.Equals(row["ProjectUID"].ToString())
                                         select e).Count();
                            if (count == 0 && groups.Count > 0)
                            {
                                scope.Transaction.Begin();
                                var new_proj_row = new Projects();
                                new_proj_row.name = row["Title"].ToString();
                                new_proj_row.uid  = row["ProjectUID"].ToString();
                                groups[0].projects.Add(new_proj_row);
                                scope.Add(groups[0]);
                                scope.Transaction.Commit();
                            }
                        }

                        RptrProjectnames.DataSource = (from c in scope.GetOqlQuery <Users>().ExecuteEnumerable()
                                                       from d in c.groups
                                                       from f in d.projects
                                                       where
                                                       c.ResourceUID.Equals(LblCurUserUId.Text) &&
                                                       d.UID.Equals(Guid.Empty.ToString())
                                                       select f).AsEnumerable();
                        RptrProjectnames.DataBind();
                    }
                }
                catch (Exception ex)
                {
                    MyUtilities.ErrorLog("Error at Project Group Congure load due to " + ex.Message,
                                         EventLogEntryType.Error);
                    if (MyUtilities.DevelopMode)
                    {
                        Response.Write(ex.Message);
                    }
                }
            }
        }
 private void LoadReceiptValuesFromDb(IObjectScope scope)
 {
     var modeofpayments = new List<string> { "Cash", "Cheque", "Online", "Mobile", "Goods" };
     ViewData["modeOfPayment"] = modeofpayments;
     var receivers = (from c in scope.GetOqlQuery<User>().ExecuteEnumerable()
                      where c.IsheDonationReceiver.Equals(true)
                      select c).ToList();
     var donationReceivers = receivers.Select(receiver => receiver.Username).ToList();
     ViewData["donationReceivers"] = donationReceivers;
 }
Beispiel #22
0
        public static bool PlaceProject(string groupuid, string projectuid, string currentuseruid)
        {
            bool Output = false;

            try
            {
                // open access dynamic databse configuration
                string SiteUrl = HttpContext.Current.Request.UrlReferrer.Scheme + "://" +
                                 HttpContext.Current.Request.UrlReferrer.Host + ":" +
                                 HttpContext.Current.Request.UrlReferrer.Port + "/" +
                                 HttpContext.Current.Request.UrlReferrer.Segments[1];
                if (MyUtilities.DevelopMode)
                {
                    SiteUrl = MyUtilities.ProjectServerInstanceURL(SPContext.Current);
                }

                MyUtilities.ModifyConnectionString(SiteUrl);

                using (IObjectScope scope = ObjectScopeProvider1.GetNewObjectScope())
                {
                    List <Projects> projects = (from c in scope.GetOqlQuery <Users>().ExecuteEnumerable()
                                                from d in c.groups
                                                from f in d.projects
                                                where c.ResourceUID.Equals(currentuseruid) && f.uid.Equals(projectuid)
                                                select f).ToList();
                    if (projects.Count > 0)
                    {
                        List <Groups> new_groups = (from c in scope.GetOqlQuery <Users>().ExecuteEnumerable()
                                                    from d in c.groups
                                                    where c.ResourceUID.Equals(currentuseruid) && d.UID.Equals(groupuid)
                                                    select d).ToList();
                        if (new_groups.Count > 0)
                        {
                            List <Groups> old_groups = (from c in scope.GetOqlQuery <Users>().ExecuteEnumerable()
                                                        from d in c.groups
                                                        from f in d.projects
                                                        where c.ResourceUID.Equals(currentuseruid) && f.uid.Equals(projectuid)
                                                        select d).ToList();
                            // remove from current group first
                            if (old_groups.Count > 0)
                            {
                                if (old_groups[0].projects.Contains(projects[0]))
                                {
                                    scope.Transaction.Begin();
                                    old_groups[0].projects.Remove(projects[0]);
                                    scope.Add(old_groups[0]);
                                    scope.Transaction.Commit();
                                }
                            }

                            scope.Transaction.Begin();
                            new_groups[0].projects.Add(projects[0]);
                            scope.Add(new_groups[0]);
                            scope.Transaction.Commit();
                            Output = true;
                        }
                    }
                }
            }
            catch (Exception)
            {
                // error log here
            }
            return(Output);
        }
 private static bool Checkauthorization(IObjectScope scope, string username)
 {
     List<User> users = (from c in scope.GetOqlQuery<User>().ExecuteEnumerable()
                         where c.Username.ToLower().Equals(username.ToLower())
                         select c).ToList();
     if (users.Count > 0 && users[0].IsheAdmin)
         return true;
     return false;
 }
 private Employee ResolveEmployeeByName(IObjectScope objScope, string name)
 {
     Employee e = null;
     const string queryEmployeeByName = "ELEMENT (SELECT o FROM EmployeeExtent AS o WHERE o.Name = $1)";
     IQuery oqlQuery = objScope.GetOqlQuery(queryEmployeeByName);
     using (IQueryResult result = oqlQuery.Execute(name))
     {
         if (result.Count > 0)
             e = result[0] as Employee;
     }
     return e;
 }
        private MembershipUserCollection QueryMembershipUsers(IObjectScope objScope, string oqlQuery, string likeValue, int pageIndex, int pageSize, out int totalRecords)
        {
            MembershipUserCollection users = new MembershipUserCollection();
            IQuery query = objScope.GetOqlQuery(oqlQuery);
            IQueryResult result;
            if (likeValue != null)
                result = query.Execute(likeValue + '*'); // OQL use * as wildcard instead of %
            else
                result = query.Execute();

            using (result)
            {
                totalRecords = result.Count;
                int counter = 0;
                int startIndex = pageSize * pageIndex;
                int endIndex = startIndex + pageSize - 1;

                foreach (object res in result)
                {
                    if (counter >= startIndex)
                    {
                        Employee e = res as Employee;
                        users.Add(GetUserFromEmployee(e));
                    }
                    if (counter >= endIndex)
                        break;
                    counter += 1;
                }
            }
            return users;
        }
Beispiel #26
0
        private ProfileInfoCollection QueryProfileInfos(IObjectScope objScope, string oqlQuery, object oqlValue, int pageIndex, int pageSize, out int totalRecords)
        {
            ProfileInfoCollection pic = new ProfileInfoCollection();
            IQuery query = objScope.GetOqlQuery(oqlQuery);

            IQueryResult result;
            if (oqlValue != null)
                result = query.Execute(oqlValue);
            else
                result = query.Execute();

            using (result)
            {
                totalRecords = result.Count;
                int counter = 0;
                int startIndex = pageSize * pageIndex;
                int endIndex = startIndex + pageSize - 1;

                foreach (object res in result)
                {
                    if (counter >= startIndex)
                    {
                        EmployeeProfile ep = res as EmployeeProfile;
                        pic.Add(new ProfileInfo(ep.Employee.Name, false, ep.Employee.LastActivityDate, ep.LastUpdatedDate, 0));
                    }
                    if (counter >= endIndex)
                        break;
                    counter += 1;
                }
            }
            return pic;
        }
 private bool Checkauthorization(IObjectScope scope, string username)
 {
     List<User> users = (from c in scope.GetOqlQuery<User>().ExecuteEnumerable()
                         where c.Username.ToLower().Equals(username.ToLower())
                         select c).ToList();
     if (users.Count > 0 && (users[0].IsheDonationReceiver || users[0].IsheAdmin))
     {
         ViewData["IsheAdmin"] = users[0].IsheAdmin;
         ViewData["IsheDonationReceiver"] = users[0].IsheDonationReceiver;
         return true;
     }
     ViewData["IsheAdmin"] = false;
     ViewData["IsheDonationReceiver"] = false;
     return false;
 }
    protected void Page_Load(object sender, EventArgs e)
    {
        ApiContext context = new ApiContext(new Guid("e5c5c78b-9e7a-4759-8dd6-ceaf46a2b855"), "http://api.brafton.com/");
        var news = context.News;
        var categories = context.Categories;
        //IList<newsItem> newsItems = new List<newsItem>();
        //IList<category> categoryItems = new List<category>();
        objectScope = BraftonContext.GetNewObjectScope();

        foreach (category item in categories)
        {
            bool isNew = false;
            objectScope.Transaction.Begin();
            Category cat = GetCategory(item, out isNew);
            cat = LoadCategoryItem(item, cat);
            if (isNew)
                objectScope.Add(cat);
            objectScope.Transaction.Commit();
        }

        foreach (newsItem item in news)
        {
            var cats = item.categories;
            objectScope.Transaction.Begin();
            bool isNew = false;
            NewsItem _item = GetNewsItem(item, out isNew);
            _item = LoadNewsItem(item, _item);
            if (isNew)
                objectScope.Add(_item);
            objectScope.Transaction.Commit();
        }

        string query = "select * from NewsItemExtent AS x";

        IQuery queryForExecution = objectScope.GetOqlQuery(query);
        queryForExecution.ForwardsOnly = false;
        IQueryResult res = queryForExecution.Execute();
        if (res.Count > 0)
        {
            for (int i = 0; i < res.Count; i++)
            {
                NewsItem item = (NewsItem)res[i];
                ltrlItems.Text += "<a href=\"news/" + item.Url + "\">" + item.Headline + "</a><br /><p>" + item.Extract + "</p>";
            }
        }
    }
Beispiel #29
0
 private EmployeeProfile ResolveEmployeeProfileByName(IObjectScope objScope, string userName)
 {
     if (null == userName) return null;
     EmployeeProfile ep = null;
     const string queryEmployeeProfile =
     @"ELEMENT (SELECT * FROM EmployeeProfileExtent AS o WHERE o.Employee.Name = $1)";
     IQuery oqlQuery = objScope.GetOqlQuery(queryEmployeeProfile);
     using (IQueryResult result = oqlQuery.Execute(userName))
         if (result.Count > 0)
             ep = result[0] as EmployeeProfile;
     return ep;
 }
Beispiel #30
0
 private Employee ResolveEmployeeByName(IObjectScope objScope, string name)
 {
     Employee e = null;
     const string queryEmployeeByName =
     @"ELEMENT (SELECT o FROM EmployeeExtent AS o WHERE o.Name = $1 AND o.IsApproved = true AND o.isLockedOut = false)";
     IQuery oqlQuery = objScope.GetOqlQuery(queryEmployeeByName);
     using (IQueryResult result = oqlQuery.Execute(name))
     {
         if (result.Count > 0)
             e = result[0] as Employee;
         else
             throw new ProviderException(string.Format(MSG.ProfileProvider_Employee_Not_Exist,name));
     }
     return e;
 }
Beispiel #31
0
 private Role ResolveRoleByName(IObjectScope objScope, string roleName)
 {
     if (null == roleName) return null;
     Role r = null;
     const string queryRole = @"ELEMENT (SELECT * FROM RoleExtent AS o WHERE o.Name = $1)";
     IQuery oqlQuery = objScope.GetOqlQuery(queryRole);
     using (IQueryResult result = oqlQuery.Execute(roleName))
     {
         if (result.Count > 0)
             r = result[0] as Role;
     }
     return r;
 }