Example #1
0
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            await _writer.AddAsync(Module);

            return(RedirectToPage("./Index"));
        }
Example #2
0
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }


            try
            {
                await _writer.AddAsync(UserCourses);
            }
            catch
            {
                ViewData["Users"]        = _reader.GetSelectList <User>("Id", "Email");
                ViewData["Courses"]      = _reader.GetSelectList <Course>("Id", "Title");
                ViewData["ErrorMessage"] = "User has already taken this course";
                return(Page());
            }
            return(RedirectToPage("./Index"));
        }
Example #3
0
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            try
            {
                var success = await _writer.AddAsync(UserProducts);                 //LÄGG TILL I SERVICEN

                if (success)
                {
                    return(RedirectToPage("./Index"));                    // Kan även läggas till i catch blocket nedan
                }
            }
            catch { }
            ViewData["Users"]    = _reader.GetSelectList <User>("Id", "Email");
            ViewData["Products"] = _reader.GetSelectList <Product>("Id", "Name");

            return(Page());
        }