Пример #1
0
        public GetTeamResponse.Team CreateTeam(string project, string newTeam)
        {
            GetTeamResponse.Team viewModel = new GetTeamResponse.Team();
            TeamPost             team      = new TeamPost()
            {
                name = newTeam
            };

            using (var client = new HttpClient())
            {
                client.DefaultRequestHeaders.Accept.Clear();
                client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json"));
                client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials);

                // serialize the fields array into a json string
                var patchValue = new StringContent(JsonConvert.SerializeObject(team), Encoding.UTF8, "application/json"); // mediaType needs to be application/json-patch+json for a patch call
                var method     = new HttpMethod("POST");

                var request = new HttpRequestMessage(method, _configuration.UriString + "/_apis/projects/" + project + "/teams?api-version=2.2")
                {
                    Content = patchValue
                };
                var response = client.SendAsync(request).Result;

                if (response.IsSuccessStatusCode)
                {
                    viewModel = response.Content.ReadAsAsync <GetTeamResponse.Team>().Result;
                }

                viewModel.HttpStatusCode = response.StatusCode;

                return(viewModel);
            }
        }
Пример #2
0
        public ActionResult CreateTeamPost(int teamId, string post)
        {
            ITeamService teamService = new TeamService(new RepositoryGroup(), false);
            var          team        = _teamService.GetTeamById(teamId);

            if (team == null)
            {
                Response.StatusCode = 403;
                return(Content("Invalid TeamId Submitted"));
            }
            if (CurrentUser != null && team.Registrations.FirstOrDefault(x => x.UserId == CurrentUser.UserId) != null)
            {
                var teamPost = new TeamPost {
                    TeamId = teamId, Post = post, UserId = CurrentUser.UserId
                };
                var dbResult = teamService.CreateTeamPost(teamPost);
                if (dbResult.Success)
                {
                    //success
                    var teamRefresh = _teamService.GetTeamById(teamId);

                    var entity = teamRefresh.TeamPosts.OrderBy(x => x.DateAdded).ToList();

                    return(PartialView("Partial/MessageBoardPosts", entity));
                }
                Response.StatusCode = 500;
                return(Content("Invalid TeamId Submitted"));
            }
            Response.StatusCode = 403;
            return(Content("Only members of a team may post messages."));
        }
Пример #3
0
        public ServiceResult CreateTeamPost(TeamPost teamPost)
        {
            var result = new ServiceResult();

            if (teamPost == null || teamPost.TeamId <= 0 || teamPost.UserId <= 0)
            {
                throw new ArgumentException("TeamPost must contain a valid TeamId and User Id", "teamPost");
            }

            try
            {
                var team = this.GetTeamById(teamPost.TeamId);
                teamPost.DateAdded = DateTime.Now;
                _repository.TeamPosts.Create(teamPost);
                _repository.SaveChanges();
            }
            catch (Exception ex)
            { result.AddServiceError(Utilities.GetInnerMostException(ex)); }
            return(result);
        }