Exemplo n.º 1
0
        public ActionResult EditGoal(GroupGoalFormModel editGoal)
        {
            GroupGoal groupGoal = Mapper.Map<GroupGoalFormModel, GroupGoal>(editGoal);
            var errors = groupGoalService.CanAddGoal(groupGoal, groupUpdateService);
            ModelState.AddModelErrors(errors);
            if (ModelState.IsValid)
            {
                groupGoalService.EditGroupGoal(groupGoal);
                return RedirectToAction("GroupGoal", new { id = editGoal.GroupGoalId }); ;

            }
            else
            {
                var metrics = metricService.GetMetrics();
                var focuss = focusService.GetFocuss();
                var groupGoalToEdit = groupGoalService.GetGroupGoal(editGoal.GroupGoalId);
                editGoal.Group = groupService.GetGroup(editGoal.GroupId);
                if (groupGoalToEdit.Metric != null)
                    editGoal.Metrics = metrics.ToSelectListItems(groupGoalToEdit.Metric.MetricId);
                else
                    editGoal.Metrics = metrics.ToSelectListItems(-1);
                if (groupGoalToEdit.Focus != null)
                    editGoal.Foci = focuss.ToSelectListItems(groupGoalToEdit.Focus.FocusId);
                else
                    editGoal.Foci = focuss.ToSelectListItems(-1);
                //editGoal.Group = groupGoalToEdit.GroupUser.Group;
                return View(editGoal);
            }
        }
Exemplo n.º 2
0
 public ActionResult CreateGoal(GroupGoalFormModel goal)
 {
     GroupGoal groupgoal = Mapper.Map<GroupGoalFormModel, GroupGoal>(goal);
     var groupUser = groupUserService.GetGroupUser(User.Identity.GetUserId(), goal.GroupId);
     groupgoal.GroupUserId = groupUser.GroupUserId;
     //groupgoal.GroupUser = groupUser;
     //if (groupgoal.AssignedTo == null)
     //{
     //    groupgoal.AssignedGroupUserId = null;
     //}
     var errors = groupGoalService.CanAddGoal(groupgoal, groupUpdateService).ToList();
     ModelState.AddModelErrors(errors);
     if (ModelState.IsValid)
     {
         //groupgoal.GroupUser.UserId = ((SocialGoalUser)(User.Identity)).UserId;
         groupGoalService.CreateGroupGoal(groupgoal);
         return RedirectToAction("Index", new { id = goal.GroupId });
     }
     //goal.Group = groupService.GetGroup(goal.GroupUser.GroupId);
     var metrics = metricService.GetMetrics();
     var focuss = focusService.GetFocussOFGroup(goal.GroupId);
     goal.Metrics = metrics.ToSelectListItems(-1);
     goal.Foci = focuss.ToSelectListItems(-1);
     return View(goal);
 }
Exemplo n.º 3
0
 //[ActionName("CreateGoal")]
 public ViewResult CreateGoal(int id)
 {
     var metrics = metricService.GetMetrics();
     var focuss = focusService.GetFocussOFGroup(id);
     var groupGoal = new GroupGoalFormModel() { GroupId = id };
     groupGoal.Metrics = metrics.ToSelectListItems(-1);
     groupGoal.Foci = focuss.ToSelectListItems(-1);
     return View(groupGoal);
 }
Exemplo n.º 4
0
        public void Create_Goal()
        {
            MemoryUser user = new MemoryUser("adarsh");
            ApplicationUser applicationUser = getApplicationUser();
            var userContext = new UserInfo
            {
                UserId = user.Id,
                DisplayName = user.UserName,
                UserIdentifier = applicationUser.Email,
                RoleName = Enum.GetName(typeof(UserRoles), applicationUser.RoleId)
            };
            var testTicket = new FormsAuthenticationTicket(
                1,
                user.Id,
                DateTime.Now,
                DateTime.Now.Add(FormsAuthentication.Timeout),
                false,
                userContext.ToString());
            GroupController controller = new GroupController(groupService, groupUserService, userService, metricService, focusService, groupgoalService, groupInvitationService, securityTokenService, groupUpdateService, groupCommentService, goalStatusService, groupRequestService, followUserService, groupCommentUserService, groupUpdateSupportService, groupUpdateUserService);
            principal.SetupGet(x => x.Identity.Name).Returns("adarsh");
            controllerContext.SetupGet(x => x.HttpContext.User).Returns(principal.Object);
            controllerContext.SetupGet(p => p.HttpContext.Request.IsAuthenticated).Returns(true);
            controller.ControllerContext = controllerContext.Object;

            contextBase.SetupGet(x => x.Request).Returns(httpRequest.Object);
            contextBase.SetupGet(x => x.Response).Returns(httpResponse.Object);
            genericPrincipal.Setup(x => x.Identity).Returns(identity.Object);

            contextBase.SetupGet(a => a.Response.Cookies).Returns(new HttpCookieCollection());

            var formsAuthentication = new DefaultFormsAuthentication();



            formsAuthentication.SetAuthCookie(contextBase.Object, testTicket);

            HttpCookie authCookie = contextBase.Object.Response.Cookies[FormsAuthentication.FormsCookieName];

            var ticket = formsAuthentication.Decrypt(authCookie.Value);
            var goalsetterUser = new SocialGoalUser(ticket);
            string[] userRoles = { goalsetterUser.RoleName };

            principal.Setup(x => x.Identity).Returns(goalsetterUser);
            GroupUser grpuser = new GroupUser()
            {
                GroupId = 1,
                UserId = "402bd590-fdc7-49ad-9728-40efbfe512ec"
            };
            groupUserRepository.Setup(x => x.Get(It.IsAny<Expression<Func<GroupUser, bool>>>())).Returns(grpuser);


            // Act
            Mapper.CreateMap<GroupGoalFormModel, GroupGoal>();

            GroupGoalFormModel goal = new GroupGoalFormModel()
            {
                GoalName = "t",
                GroupGoalId = 1,
                StartDate = DateTime.Now,
                EndDate = DateTime.Now.AddDays(1),
                Description = "t",
                GroupId = 1,
                GroupUserId = 1,


            };
            var result = (RedirectToRouteResult)controller.CreateGoal(goal);


            Assert.AreEqual("Index", result.RouteValues["action"]);


        }
Exemplo n.º 5
0
        public void Create_Goal_Get_ReturnsView()
        {

            IEnumerable<Focus> fakeFocus = new List<Focus> 
            {
            new Focus { FocusId = 1, FocusName="Test1",GroupId = 1},
             new Focus { FocusId = 2, FocusName="Test2",GroupId = 1},
            new Focus { FocusId = 3, FocusName="Test3",GroupId = 1}
          }.AsEnumerable();
            focusRepository.Setup(x => x.GetMany(It.IsAny<Expression<Func<Focus, bool>>>())).Returns(fakeFocus);

            IEnumerable<Metric> fakeMatrices = new List<Metric> 
            {
                new Metric{MetricId=1, Type="Test1"},
                new Metric{MetricId=2,Type="Test2"},
                new Metric{MetricId=3,Type="Test3"}
            }.AsEnumerable();

            metricRepository.Setup(x => x.GetAll()).Returns(fakeMatrices);
            GroupGoalFormModel goal = new GroupGoalFormModel();
            GroupController controller = new GroupController(groupService, groupUserService, userService, metricService, focusService, groupgoalService, groupInvitationService, securityTokenService, groupUpdateService, groupCommentService, goalStatusService, groupRequestService, followUserService, groupCommentUserService, groupUpdateSupportService, groupUpdateUserService);

            ViewResult result = controller.CreateGoal(1) as ViewResult;

            Assert.IsNotNull(result, "View Result is null");
            Assert.IsInstanceOf(typeof(GroupGoalFormModel),
                result.ViewData.Model, "Wrong View Model");


        }
Exemplo n.º 6
0
        public void Edit_Goal_Post()
        {

            GroupController controller = new GroupController(groupService, groupUserService, userService, metricService, focusService, groupgoalService, groupInvitationService, securityTokenService, groupUpdateService, groupCommentService, goalStatusService, groupRequestService, followUserService, groupCommentUserService, groupUpdateSupportService, groupUpdateUserService);

            Mapper.CreateMap<GroupGoalFormModel, GroupGoal>();

            GroupGoalFormModel goal = new GroupGoalFormModel()
            {
                GoalName = "t",
                GroupGoalId = 1,
                StartDate = DateTime.Now,
                EndDate = DateTime.Now.AddDays(1),
                Description = "t",
                GroupId = 1,
                GroupUserId = 1

            };
            var result = (RedirectToRouteResult)controller.EditGoal(goal);
            Assert.AreEqual("GroupGoal", result.RouteValues["action"]);



        }