Ejemplo n.º 1
0
        /// <summary>
        ///     Indexes the specified page.
        /// </summary>
        /// <param name="page">The page.</param>
        /// <returns>
        ///     Task{ActionResult}.
        /// </returns>
        public async Task <ActionResult> Index(int?page)
        {
            var       pageNumber     = page ?? 0;
            const int MissionsOnPage = 15;
            var       selectOptions  = new QueryOptions <Mission>
            {
                /*Filter = p => p.Author == "Defor",*/
                Skip   = pageNumber * MissionsOnPage,
                Top    = MissionsOnPage + 1,
                Select =
                    draft =>
                    new
                {
                    draft.Id,
                    draft.Name,
                    draft.Description,
                    draft.PhotoUrl,
                    draft.AgeFrom,
                    draft.AgeTo,
                    draft.Difficulty
                }
            };

            Expression <Func <Mission, string> > z = x => x.Name;

            selectOptions.OrderBy = new List <SortDescription> {
                new SortDescription(z, SortDirection.Ascending)
            };

            var missions = await _missionService.GetMissions(selectOptions);

            IEnumerable <Mission> model;

            if (missions.Count <= MissionsOnPage)
            {
                ViewBag.ShowNext = false;
                model            = missions;
            }
            else
            {
                ViewBag.ShowNext = true;
                model            = missions.Take(MissionsOnPage);
            }

            ViewBag.ShowPrevious = pageNumber != 0;
            ViewBag.CurrentPage  = pageNumber;
            return(View(model));
        }
Ejemplo n.º 2
0
        public async Task ConvertDraftToMission()
        {
            // Действие
            var result = (await _controller.Index(null)) as ViewResult;
            var drafts = result.Model as IEnumerable <MissionDraft>;
            var draft  = drafts.First();

            var actionResult = (await _controller.CreateMissionFromDraft(draft.Id)) as RedirectToRouteResult;

            Assert.NotNull(actionResult);

            result = (await _controller.Index(null)) as ViewResult;
            var draftsAfterDelete = result.Model as IEnumerable <MissionDraft>;
            var oldDraft          = draftsAfterDelete.FirstOrDefault(dr => dr.Id == draft.Id);

            var newMission =
                await _missionService.GetMissions(
                    new QueryOptions <Mission> {
                Filter = mission => mission.Name == draft.Name
            });

            // Утверждение
            Assert.IsNull(oldDraft);
            Assert.IsNotEmpty(newMission);
            Assert.NotNull(newMission.First());
        }
Ejemplo n.º 3
0
        public async Task CreateRightAnswerMission()
        {
            // Действие
            var missions = await _service.GetMissions();

            int count = missions.Count;

            var newMission = new MissionUi
            {
                Name           = "RightAnswer mission",
                Description    = "RightAnswer",
                PhotoUrl       = "https://pp.vk.me/c543109/v543109262/11668/-YwppEKJVx0.jpg",
                Difficulty     = 1,
                ExecutionType  = ExecutionType.RightAnswer,
                CorrectAnswers = "один;два",
                AgeFrom        = 10,
                AgeTo          = 80
            };

            await _controller.Create(newMission);

            missions = await _service.GetMissions();

            // Утверждение
            Assert.IsNotEmpty(missions);
            Assert.AreEqual("RightAnswer mission", missions.Last().Name);
            Assert.AreEqual(count + 1, missions.Count);
        }
Ejemplo n.º 4
0
        private async Task <Dictionary <string, string> > GetBaseMissions()
        {
            var selectOptions = new QueryOptions <Mission> {
                Select = m => new { m.Id, m.Name }
            };
            Expression <Func <Mission, string> > z = x => x.Name;

            selectOptions.OrderBy = new List <SortDescription> {
                new SortDescription(z, SortDirection.Ascending)
            };

            var missions = await _missionService.GetMissions(selectOptions);

            var currentMissions = GetCurrentMissionsFromTempData();

            var result = missions.Where(m => string.IsNullOrEmpty(m.MissionSetId) || currentMissions.Contains(m.Id))
                         .ToDictionary(m => m.Id, m => m.Name);

            return(result);
        }