Example #1
0
        //public List<VMActivity> MapActivities(IList<Activity> data,MogController controler)
        public List <VMActivity> MapActivities(IList <Activity> data)
        {//TOdo : use automapper
            List <VMActivity> result = new List <VMActivity>();

            foreach (var activity in data)
            {
                VMActivity oneActivity = new VMActivity()
                {
                    Id   = activity.Id,
                    When = activity.When,
                    Who  = activity.Who,
                    Type = activity.Type & (ActivityType.Project | ActivityType.Comment | ActivityType.File)
                };

                if ((activity.Type & ActivityType.Comment) == ActivityType.Comment &&
                    (activity.Type & ActivityType.Create) == ActivityType.Create)
                {//
                    oneActivity.Description = String.Format("<strong>{0}</strong>  {2} <strong>{1}</strong>",
                                                            activity.Who.DisplayName,
                                                            activity.File.DisplayName,
                                                            Resources.Resource.ACTIVITY_CommentedFile);

                    oneActivity.Url = "/File/Display/" + activity.FileId.Value;//controler.Url.Action("Display", "File", new { id = activity.FileId.Value });
                }

                if ((activity.Type & ActivityType.File) == ActivityType.File &&
                    (activity.Type & ActivityType.Create) == ActivityType.Create)
                {//
                    oneActivity.Description = String.Format("<strong>{0}</strong> {2} <strong>{1}</strong>",
                                                            activity.Who.DisplayName,
                                                            activity.File.DisplayName,
                                                            Resources.Resource.ACTIVITY_CreatedFile);

                    oneActivity.Url = "File/Display/" + activity.FileId.Value;//controler.Url.Action("Display", "File", new { id = activity.FileId.Value });
                }

                if ((activity.Type & ActivityType.Project) == ActivityType.Project &&
                    (activity.Type & ActivityType.Create) == ActivityType.Create)
                {//
                    oneActivity.Description = String.Format("<strong>{0}</strong> {2} <strong>{1}</strong>",
                                                            activity.Who.DisplayName,
                                                            activity.Project.Name,
                                                            Resources.Resource.ACTIVITY_CreatedProject);

                    oneActivity.Url = "Project/Detail/" + activity.ProjectId.Value;//controler.Url.Action("Detail", "Project", new { id = activity.ProjectId.Value });
                }


                result.Add(oneActivity);
            }
            return(result);
        }
        // GET: GuestDashboard
        public async Task <ActionResult> Index(int regionId = 0)
        {
            HttpContext.Session.SetString("CurrentUser", Guid.NewGuid().ToString());
            HttpContext.Session.CommitAsync().Wait();
            var lstRegions = await _service.GetRegions();

            lstRegions.Add(new SelectListItem()
            {
                Text = "All", Value = "0"
            });
            var listofActivities = await _service.GetActivities(regionId); //send region id

            VMActivity vmactivity = new VMActivity();

            vmactivity.Activities     = listofActivities;
            vmactivity.Regions        = lstRegions.OrderBy(x => x.Value).ToList();
            vmactivity.RegionSelected = regionId.ToString();
            return(this.View(vmactivity));
        }
        public async Task <IActionResult> FilterActivities(VMActivity activityFilter)
        {
            if (activityFilter != null)
            {
                if (!string.IsNullOrEmpty(activityFilter.RegionSelected))
                {
                    if (activityFilter.RegionSelected == "0")
                    {
                        return(RedirectToAction("Index", new { regionId = 0 }));
                    }
                    else
                    {
                        int region_id = Convert.ToInt32(activityFilter.RegionSelected);
                        return(RedirectToAction("Index", new { regionId = region_id }));
                    }
                }
            }

            return(RedirectToAction("Index", new { regionId = 0 }));
        }
        public async Task FilterActivities_withRegionId_Success()
        {
            //Arrange
            List <SelectListItem> lstRegions = new List <SelectListItem>()
            {
                new SelectListItem {
                    Text  = "all",
                    Value = "0"
                },
                new SelectListItem {
                    Text  = "region1",
                    Value = "1"
                },
                new SelectListItem {
                    Text  = "region2",
                    Value = "2"
                },
            };
            List <VMActivityDetails> lstActivities = new List <VMActivityDetails>()
            {
                new VMActivityDetails
                {
                    activity_id          = 1,
                    activity_name        = "test",
                    activity_slots       = 10,
                    activity_description = "test desc",
                    activity_fee         = 500,
                    activity_season      = "Winter"
                },
                new VMActivityDetails
                {
                    activity_id          = 2,
                    activity_name        = "test2",
                    activity_slots       = 100,
                    activity_description = "test desc 2",
                    activity_fee         = 50,
                    activity_season      = "Winter"
                }
            };

            IDictionary <string, List <VMActivityDetails> > otpActivities = new Dictionary <string, List <VMActivityDetails> >();

            otpActivities.Add("SA", lstActivities);
            otpActivities.Add("RA", lstActivities);
            otpActivities.Add("RB", lstActivities);

            mockSession();

            _service.Setup(x => x.GetRegions()).Returns(Task.FromResult(lstRegions));
            _service.Setup(x => x.GetActivities(It.IsAny <int>())).Returns(Task.FromResult(otpActivities));

            VMActivity input = new VMActivity()
            {
                RegionSelected = "1"
            };

            //Act
            var result = await controller.FilterActivities(input) as RedirectToActionResult;

            //Assert
            Assert.Equal("Index", result.ActionName);
        }