Beispiel #1
0
        public JsonResult ConfigureAppForCI(int id, bool shouldConfigure)
        {
            if (!Repository.Managers.ApplicationBuildMgr.IsUserAnAppTeamMember(User.Identity.GetUserName(), id))
            {
                throw new HttpException(403, "You are not a team member of this app.");
            }

            Repository.TeamMember CIUser = Repository.Managers.ApplicationMgr.GetSystemCIUser();
            try
            {
                if (shouldConfigure)
                {
                    //Check to make sure the CI user is not already a member of the APP
                    if (!Repository.Managers.ApplicationBuildMgr.IsUserAnAppTeamMember(CIUser.UserName, id))
                    {
                        using (var context = new Repository.BetaDepotContext())
                        {
                            Repository.Application           app        = context.Applications.Where(w => w.Id == id).FirstOrDefault();
                            Repository.ApplicationTeamMember membership = new Repository.ApplicationTeamMember()
                            {
                                TeamMember = CIUser,
                                MemberRole = Common.Constants.APPLICATION_MEMBER_ROLE_CONTINUOUS_INTEGRATION
                            };

                            app.AssignedMembers.Add(membership);
                            context.SaveChanges();
                        }
                    }
                }
                else
                {
                    //Check to make sure the CI user is not already a member of the APP
                    if (Repository.Managers.ApplicationBuildMgr.IsUserAnAppTeamMember(User.Identity.GetUserName(), id))
                    {
                        using (var context = new Repository.BetaDepotContext())
                        {
                            Repository.Application app = context.Applications.Where(w => w.Id == id).FirstOrDefault();
                            app.AppToken = null;
                            Repository.ApplicationTeamMember membership = context.ApplicationTeamMembers
                                                                          .Where(w => w.TeamMember.UserName.ToLower() == CIUser.UserName)
                                                                          .FirstOrDefault();

                            app.AssignedMembers.Remove(membership);
                            context.SaveChanges();
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                return(Json(new { Msg = Common.Constants.APPLICATION_JSON_RESULT_ERROR }));
            }


            return(Json(new { Msg = Common.Constants.APPLICATION_JSON_RESULT_SUCCESS }));
        }
        public JsonResult ConfigureAppForCI(int id, bool shouldConfigure)
        {
            if (!Repository.Managers.ApplicationBuildMgr.IsUserAnAppTeamMember(User.Identity.GetUserName(), id))
                throw new HttpException(403, "You are not a team member of this app.");

            Repository.TeamMember CIUser = Repository.Managers.ApplicationMgr.GetSystemCIUser();
            try
            {
                if (shouldConfigure)
                {
                    //Check to make sure the CI user is not already a member of the APP
                    if (!Repository.Managers.ApplicationBuildMgr.IsUserAnAppTeamMember(CIUser.UserName, id))
                    {
                        using (var context = new Repository.BetaDepotContext())
                        {
                            Repository.Application app = context.Applications.Where(w => w.Id == id).FirstOrDefault();
                            Repository.ApplicationTeamMember membership = new Repository.ApplicationTeamMember()
                            {
                                TeamMember = CIUser,
                                MemberRole = Common.Constants.APPLICATION_MEMBER_ROLE_CONTINUOUS_INTEGRATION
                            };

                            app.AssignedMembers.Add(membership);
                            context.SaveChanges();
                        }
                    }
                }
                else
                {
                    //Check to make sure the CI user is not already a member of the APP
                    if (Repository.Managers.ApplicationBuildMgr.IsUserAnAppTeamMember(User.Identity.GetUserName(), id))
                    {
                        using (var context = new Repository.BetaDepotContext())
                        {
                            Repository.Application app = context.Applications.Where(w => w.Id == id).FirstOrDefault();
                            app.AppToken = null;
                            Repository.ApplicationTeamMember membership = context.ApplicationTeamMembers
                                                                                .Where(w => w.TeamMember.UserName.ToLower() == CIUser.UserName)
                                                                                .FirstOrDefault();

                            app.AssignedMembers.Remove(membership);
                            context.SaveChanges();
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                return Json(new { Msg = Common.Constants.APPLICATION_JSON_RESULT_ERROR });
            }


            return Json(new { Msg = Common.Constants.APPLICATION_JSON_RESULT_SUCCESS });
        }