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

            if (Course.Id == 0)
            {
                var result = await coursesProvider.AddAsync(Course);

                if (result.IsSuccess)
                {
                    return(RedirectToPage("Courses"));
                }
                return(null);
            }
            else
            {
                var result = await coursesProvider.UpdateAsync(Course.Id, Course);

                if (result)
                {
                    return(RedirectToPage("Courses"));
                }
            }


            return(null);
        }
Example #2
0
        public async Task <IActionResult> OnPost()
        {
            // Validate the form
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            // Id is 0, if it's creating a new course
            if (Course.Id == 0)
            {
                // Add the course at the course list
                var result = await coursesProvider.AddAsync(Course);

                // IsSuccess return true or false depending if the course  did update
                if (result.IsSuccess)
                {
                    return(RedirectToPage("Courses"));
                }

                return(Page());
            }
            else
            {
                // Return true or false depending if the course  did update
                var result = await coursesProvider.UpdateAsync(Course.Id, Course);

                if (result)
                {
                    return(RedirectToPage("Courses"));
                }
            }

            return(Page());
        }
Example #3
0
        public async Task <IActionResult> AddAsync(Course course)
        {
            if (course == null)
            {
                return(BadRequest());
            }
            var result = await coursesProviders.AddAsync(course);

            if (result.isSuccess)
            {
                return(Ok(result.Id));
            }
            return(NotFound());
        }