コード例 #1
0
        public IActionResult Create()
        {
            CreateWordInEnglishViewModel newWord = new CreateWordInEnglishViewModel
            {
                StagesOfMethod = new SelectList(StageOfMethodsContext.GetAllIQueryableWithInclude().ToList(), "Id", "Name")
            };

            //Use for Titile in html
            ViewData["Title"] = "Добавить слово";
            //Use for head in page
            ViewBag.HeadPageText = "Добавить слово и перевод";
            //Render to View Create
            return(View(newWord));
        }
コード例 #2
0
 public IActionResult Index()
 {
     //Use for Titile in html
     ViewData["Title"] = "Создать стейдж";
     //Use for head in page
     ViewBag.HeadPageText = "Создать стейдж";
     //Get all stages from database
     return(View(StageOfMethodsContext.GetAllIQueryableWithInclude().ToList()));
 }
コード例 #3
0
        //Index view with filters
        public IActionResult Index(long?stage, string nameOfWord, SortIndexHome sortOrder = SortIndexHome.WordInEnglishAsc)
        {
            //Get data from database
            IQueryable <StageOfMethod> stagesOfMethod = StageOfMethodContext.GetAllIQueryableWithInclude();
            IQueryable <WordInEnglish> wordsInEnglish = WordsInEnglishContext.GetAllIQueryableWithInclude(w => w.StageOfMethod, w => w.TranslationOfWords);

            //Filer by StageOfMethod
            if (stage != null && stage != 0)
            {
                wordsInEnglish = wordsInEnglish.Where(w => w.StageOfMethodId == stage);
            }
            //Search word by eglish word or by his translations
            if (!String.IsNullOrEmpty(nameOfWord))
            {
                if (!Regex.IsMatch(nameOfWord, @"\P{IsCyrillic}"))
                {
                    wordsInEnglish = wordsInEnglish.Where(w => w.Name.Contains(nameOfWord));
                }
                else
                {
                    wordsInEnglish = wordsInEnglish.Where(w => w.Name.Contains(nameOfWord));
                }
            }
            //Sorting by Name of word in english and by name of stage
            //TODO add to html this possibility
            switch (sortOrder)
            {
            case SortIndexHome.WordInEnglishAsc:
                wordsInEnglish = wordsInEnglish.OrderBy(w => w.Name);
                break;

            case SortIndexHome.WordInEnglishDesc:
                wordsInEnglish = wordsInEnglish.OrderByDescending(w => w.Name);
                break;

            case SortIndexHome.StageOfMethodAsc:
                wordsInEnglish = wordsInEnglish.OrderBy(w => w.StageOfMethod.Name);
                break;

            case SortIndexHome.StageOfMethodDesc:
                wordsInEnglish = wordsInEnglish.OrderByDescending(w => w.StageOfMethod.Name);
                break;
            }
            //Add sotr add filter with data from database to view model
            IndexHomeViewModel model = new IndexHomeViewModel
            {
                Sorting        = new SortIndexHomeViewModel(sortOrder),
                Filters        = new FilterIndexHomeViewModel(stagesOfMethod.ToList(), stage, nameOfWord),
                WordsInEnglish = wordsInEnglish
            };

            return(View(model));
        }