public static async Task <List <Team> > GetTeams(string LeagueId)
        {
            List <Team> Teams = new List <Team>();

            string URL = BASE_URL + String.Format(GET_TEAMS_ENDPOINT, LeagueId);

            using (HttpClient client = new HttpClient())
            {
                HttpRequestMessage requestMessage = new HttpRequestMessage(HttpMethod.Get, URL);

                foreach (string[] customHeader in CUSTOM_HEADERS)
                {
                    requestMessage.Headers.Add(customHeader[0].ToString(), customHeader[1].ToString());
                }

                var response = await client.SendAsync(requestMessage);

                string jsonString = await response.Content.ReadAsStringAsync();

                APITeam json = JsonConvert.DeserializeObject <APITeam>(jsonString);

                Teams = json.api.teams;
            }
            return(Teams);
        }
Esempio n. 2
0
        public IHttpActionResult GetTeam(int id)
        {
            var team = _repository.GetById(id);

            if (team == null)
            {
                return(NotFound());
            }
            var result = new APITeam(team);

            return(Ok(result));
        }
        public void SetUp()
        {
            _shimsContext = ShimsContext.Create();

            InitShims();
            query.Clear();
            maxDatareaderCount     = 1;
            currentDataReaderCount = 0;

            _testEntity    = new APITeam();
            _privateObject = new PrivateObject(_testEntity);
            _privateType   = new PrivateType(typeof(APITeam));
        }
        private void FillNewFromResource(SPWeb oWeb)
        {
            var dtResources = APITeam.GetResourcePool(
                string.Format("<Get><Columns>{0}</Columns></Get>", ExternalColumn),
                oWeb);

            var arrNewTemp = new ArrayList();

            foreach (var parameter in NewUsers)
            {
                var row = dtResources.Select(string.Format("{0} ='{1}'", ExternalColumn, parameter));
                if (row.Length > 0)
                {
                    arrNewTemp.Add(row[0]["SPID"].ToString());
                }
            }

            NewUsers = arrNewTemp;
        }
Esempio n. 5
0
        /// <summary>
        ///     Maps the resource pool id to SP user id.
        /// </summary>
        /// <param name="resourcePoolIds">The resource pool ids.</param>
        /// <param name="badResourcePoolIds">The bad resource pool ids.</param>
        /// <param name="returnAll">if set to <c>true</c> [return all].</param>
        /// <returns></returns>
        private Dictionary <int, string> MapResourcePoolIdToSPUser(IEnumerable <int> resourcePoolIds,
                                                                   ref IList <string> badResourcePoolIds, bool returnAll)
        {
            var resourceIdDictionary = new Dictionary <int, string>();

            DataTable resourcePool = APITeam.GetResourcePool(@"<GetResources><Columns></Columns></GetResources>", Web);

            if (!returnAll)
            {
                foreach (int resourcePoolId in resourcePoolIds)
                {
                    DataRow dataRow = resourcePool.Select(string.Format("ID = '{0}'", resourcePoolId)).FirstOrDefault();

                    if (dataRow == null)
                    {
                        badResourcePoolIds.Add(resourcePoolId.ToString(CultureInfo.InvariantCulture));
                        continue;
                    }

                    if (!resourceIdDictionary.ContainsKey(resourcePoolId))
                    {
                        resourceIdDictionary.Add(resourcePoolId, (string)dataRow["SPAccountInfo"]);
                    }
                }
            }
            else
            {
                foreach (DataRow dataRow in resourcePool.Rows)
                {
                    int resourcePoolId = int.Parse(dataRow["ID"].ToString());

                    if (!resourceIdDictionary.ContainsKey(resourcePoolId))
                    {
                        resourceIdDictionary.Add(resourcePoolId, (string)dataRow["SPAccountInfo"]);
                    }
                }
            }

            return(resourceIdDictionary);
        }
        protected override void CreateChildControls()
        {
            if (Field == null)
            {
                return;
            }
            base.CreateChildControls();
            if (ControlMode == SPControlMode.Display)
            {
                return;
            }


            DataTable dt = new DataTable();

            dt.Columns.Add("groupname");
            dt.Columns.Add("groupid");

            SPWeb web = SPContext.Current.Web;

            SPSecurity.RunWithElevatedPrivileges(delegate()
            {
                using (SPSite eSite = new SPSite(web.Site.ID))
                {
                    using (SPWeb eWeb = eSite.OpenWeb(web.ID))
                    {
                        foreach (SPGroup group in APITeam.GetWebGroups(eWeb))
                        {
                            dt.Rows.Add(new string[] { group.Name, group.ID.ToString() });
                        }
                    }
                }
            });

            ArrayList currentValues = new ArrayList();

            try
            {
                SPFieldUserValue uv = new SPFieldUserValue(this.Web, this.ListItem["SharePointAccount"].ToString());
                foreach (SPGroup g in uv.User.Groups)
                {
                    currentValues.Add(g.ID.ToString());
                }
            }
            catch { }

            chkPerms = (CheckBoxList)this.TemplateContainer.FindControl("chkPerms");

            chkPerms.DataTextField  = "groupname";
            chkPerms.DataValueField = "groupid";
            chkPerms.DataSource     = dt;
            chkPerms.DataBind();


            foreach (ListItem i in chkPerms.Items)
            {
                if (currentValues.Contains(i.Value.ToString()))
                {
                    i.Selected = true;
                }
            }

            if (ControlMode == SPControlMode.New)
            {
                foreach (ListItem i in chkPerms.Items)
                {
                    if (i.Text == "Team Members")
                    {
                        i.Selected = true;
                    }
                }
            }
        }
Esempio n. 7
0
        private bool setPermissions(SPItemEventProperties properties, bool isAdd)
        {
            if (!properties.List.Fields.ContainsFieldWithInternalName("Permissions"))
            {
                return(false);
            }
            string curProps  = "";
            string newProps  = "";
            bool   sendEmail = false;

            try
            {
                SPFieldUserValue uv     = null;
                SPFieldUserValue uv_new = null;
                if (isAdd)
                {
                    uv = new SPFieldUserValue(properties.Web, properties.AfterProperties["SharePointAccount"].ToString());
                }
                else
                {
                    uv = new SPFieldUserValue(properties.Web, properties.ListItem["SharePointAccount"].ToString());

                    if (properties.AfterProperties["SharePointAccount"] != null)
                    {
                        uv_new = new SPFieldUserValue(properties.Web, properties.AfterProperties["SharePointAccount"].ToString());
                    }
                }

                SPUser u = uv.User;
                if (u == null)
                {
                    u = uv.User;
                    if (u == null)
                    {
                        u = properties.Web.EnsureUser(uv.LookupValue);
                    }
                }
                SPUser u_new = null;
                if (uv_new != null)
                {
                    u_new = uv_new.User;
                    if (u_new == null)
                    {
                        u_new = properties.Web.EnsureUser(uv_new.LookupValue);
                    }
                }

                // semicolon causes issues in list cleanup and potentially in other modules.
                if ((isAdd && u.Name.Contains(";")) || (!isAdd && u_new != null && u_new.Name.Contains(";")))
                {
                    throw new InvalidOperationException("Semicolon is not allowed for AD username.");
                }

                try
                {
                    curProps = properties.ListItem["Permissions"].ToString().Trim();
                }
                catch { }

                try
                {
                    newProps = properties.AfterProperties["Permissions"].ToString();
                }
                catch { return(false); }

                ArrayList arr = new ArrayList(newProps.Split(','));

                var webGroups = APITeam.GetWebGroups(properties.Web);

                foreach (SPGroup group in webGroups)
                {
                    if (arr.Contains(group.ID.ToString()))
                    {
                        try
                        {
                            group.AddUser(u);
                        }
                        catch { }
                    }
                    else
                    {
                        try
                        {
                            group.RemoveUser(u);
                        }
                        catch { }
                    }
                }


                if (!String.IsNullOrEmpty(newProps) && String.IsNullOrEmpty(curProps))
                {
                    sendEmail = true;
                }

                try
                {
                    string perms = "";
                    foreach (SPGroup wGroup in webGroups)
                    {
                        try
                        {
                            SPGroup g = u.Groups.GetByID(wGroup.ID);
                            if (g != null && arr.Contains(g.ID.ToString(CultureInfo.InvariantCulture)))
                            {
                                perms += ", " + wGroup.Name;
                            }
                        }
                        catch { }
                    }

                    properties.AfterProperties["Permissions"] = perms.Trim(", ".ToCharArray());
                }
                catch { }
            }
            catch (InvalidOperationException ex)
            {
                throw ex;
            }
            catch { }

            return(sendEmail);
        }
Esempio n. 8
0
        protected void Page_Load(object sender, EventArgs e)
        {
            SPWeb  web    = SPContext.Current.Web;
            string resUrl = "";

            web.Site.CatchAccessDeniedException = false;

            SPSecurity.RunWithElevatedPrivileges(delegate()
            {
                using (SPSite site = new SPSite(SPContext.Current.Site.ID))
                {
                    using (SPWeb aweb = site.OpenWeb(web.ID))
                    {
                        resUrl = CoreFunctions.getConfigSetting(aweb, "EPMLiveResourceURL", true, false);
                    }
                }
            });

            //bool canManageAGroup = false;
            SPListItem oLi      = null;
            SPList     oList    = null;
            bool       bUseTeam = false;

            Guid listid = Guid.Empty;
            int  itemid = 0;

            try
            {
                listid = new Guid(Request["listid"]);
                itemid = int.Parse(Request["id"]);

                oList = web.Lists[listid];
                oLi   = oList.GetItemById(itemid);
                GridGanttSettings gSettings = new GridGanttSettings(oList);
                bUseTeam = gSettings.BuildTeam;
            }
            catch (Exception)
            {
                try
                {
                    APITeam.VerifyProjectTeamWorkspace(web, out itemid, out listid);
                    if (itemid > 0 && listid != Guid.Empty)
                    {
                        try
                        {
                            while (!web.IsRootWeb) //Inherit | Open
                            {
                                if (web.IsRootWeb)
                                {
                                    break;
                                }
                                web = web.ParentWeb;
                            }

                            oList = web.Lists[listid];
                            GridGanttSettings gSettings = ListCommands.GetGridGanttSettings(oList);
                            bUseTeam = gSettings.BuildTeam;
                            oLi      = oList.GetItemById(itemid);
                        }
                        catch { }
                    }
                }
                catch { }
            }

            if (bUseTeam)
            {
                SPSecurity.RunWithElevatedPrivileges(delegate()
                {
                    using (SPSite tSite = new SPSite(web.Site.ID))
                    {
                        using (SPWeb tWeb = tSite.OpenWeb(web.ID))
                        {
                            SPListItem spListItem = null;
                            SPList tList          = tWeb.Lists[listid];
                            try
                            {
                                spListItem = tList.GetItemById(itemid);
                            }
                            catch (ArgumentException ex)
                            {
                                throw new SPException("The associated project does not exist or has been deleted.", ex);
                            }
                            web.Site.CatchAccessDeniedException = false;

                            foreach (SPRoleAssignment assn in spListItem.RoleAssignments)
                            {
                                if (assn.Member.GetType() == typeof(Microsoft.SharePoint.SPGroup))
                                {
                                    try
                                    {
                                        SPGroup group = web.SiteGroups.GetByID(assn.Member.ID);

                                        if (group.CanCurrentUserEditMembership)
                                        {
                                            string[] sG = group.Name.Split(' ');
                                            if (sG[sG.Length - 1] == "Member")
                                            {
                                                sDefaultGroup = group.ID.ToString();
                                            }

                                            bCanEditTeam = "true";
                                        }
                                    }
                                    catch { }
                                }
                            }
                        }
                    }
                });
            }
            else
            {
                foreach (SPGroup g in web.Groups)
                {
                    string[] sG = g.Name.Split(' ');
                    if (sG[sG.Length - 1] == "Member")
                    {
                        sDefaultGroup = g.ID.ToString();
                    }

                    if (g.CanCurrentUserEditMembership)
                    {
                        bCanEditTeam = "true";
                    }
                }
            }

            if (itemid > 0 && listid != Guid.Empty && PfeData.ConnectionProvider.AllowDatabaseConnections(web))
            {
                // collect pfe database project id for processing in UI part
                var repository = new PfeData.ProjectRepository();
                projectIdInPfe = repository.FindProjectId(web, listid, itemid);
            }

            if (web.Features[new Guid("84520a2b-8e2b-4ada-8f48-60b138923d01")] == null && !bUseTeam)
            {
                sDisable = "_spBodyOnLoadFunctionNames.push(\"ShowDisable\");";
                SPList teamlist = web.Lists["Team"];
                //if(web.DoesUserHavePermissions(SPBasePermissions.ManagePermissions))
                //{
                //    bCanEditTeam = "true";
                //}
            }
            else
            {
                try
                {
                    using (SPSite rsite = new SPSite(resUrl))
                    {
                        using (SPWeb rweb = rsite.OpenWeb())
                        {
                            SPList list = rweb.Lists["Resources"];
                            //DataTable dtTemp = list.Items.GetDataTable();
                            bCanAccessResourcePool = "true";
                            if (list.DoesUserHavePermissions(SPBasePermissions.AddListItems))
                            {
                                bCanAddResource = "true";
                                sNewResUrl      = list.Forms[PAGETYPE.PAGE_NEWFORM].ServerRelativeUrl;
                            }
                        }
                    }
                }
                catch { }

                XmlDocument doc = new XmlDocument();
                doc.LoadXml("<Grid/>");



                if (bUseTeam)
                {
                    try
                    {
                        if (oLi.DoesUserHavePermissions(SPBasePermissions.EditListItems))
                        {
                            bCanEditTeam = "true";
                        }

                        XmlAttribute attr = doc.CreateAttribute("WebId");
                        attr.Value = Convert.ToString(web.ID);
                        doc.FirstChild.Attributes.Append(attr);

                        attr       = doc.CreateAttribute("ListId");
                        attr.Value = Convert.ToString(listid);
                        doc.FirstChild.Attributes.Append(attr);

                        attr       = doc.CreateAttribute("ItemId");
                        attr.Value = Convert.ToString(itemid);
                        doc.FirstChild.Attributes.Append(attr);
                    }
                    catch
                    {
                    }
                }
                else
                {
                    SPList teamlist = web.Lists.TryGetList("Team");

                    if (teamlist == null)
                    {
                        web.AllowUnsafeUpdates = true;
                        web.Lists.Add("Team", "Use this list to manage your project team", SPListTemplateType.GenericList);
                        teamlist = web.Lists.TryGetList("Team");
                        try
                        {
                            teamlist.Fields.Add("ResID", SPFieldType.Number, false);
                            teamlist.Update();
                        }
                        catch { }
                    }
                }

                sLayoutParam = HttpUtility.HtmlEncode(doc.OuterXml);

                if (bCanEditTeam == "true")
                {
                    sResPool = Properties.Resources.txtBuildTeamResPool.Replace("#LayoutParam#", sLayoutParam).Replace("#DataParam#", sLayoutParam);
                    sResGrid = @"TreeGrid(   { 
                    Layout:{ Url:""../../_vti_bin/WorkEngine.asmx"",Timeout:0, Method:""Soap"",Function:""Execute"",Namespace:""workengine.com"",Param:{Function:""GetResourceGridLayout"",Dataxml:""" + sLayoutParam + @""" } } ,
                    Data:{ Url:""../../_vti_bin/WorkEngine.asmx"",Timeout:0, Method:""Soap"",Function:""Execute"",Namespace:""workengine.com"",Param:{Function:""GetResourceGridData"",Dataxml:""" + sLayoutParam + @""" } }, 
                    Debug:"""",SuppressMessage:""3""
                    }, 
	                ""divResPool"" );"    ;
                }
            }

            sUserInfoList = web.SiteUserInfoList.ID.ToString().ToUpper();

            if (Request["isDlg"] == "1")
            {
                sClose = "SP.SOD.execute('SP.UI.Dialog.js', 'SP.UI.ModalDialog.commonModalDialogClose', SP.UI.DialogResult.OK, '');";
            }
            else
            {
                if (String.IsNullOrEmpty(Request["Source"]))
                {
                    sClose = "location.href='" + ((web.ServerRelativeUrl == "/") ? "" : web.ServerRelativeUrl) + "'";
                }
                else
                {
                    sClose = "location.href='" + Request["Source"] + "'";
                }
            }
        }