예제 #1
0
        internal async Task <bool> CreateCourseEnrollmentAsync(string accountFromHeader, IEnumerable <CourseEnrollment> courseEnrollments)
        {
            try
            {
                //Workaround: AccountKey in Credentials must be provided as a request header.
                Credentials.AccountKey = accountFromHeader;

                var cEnrollments = courseEnrollments;
                var genericServiceClientHelper = new GenericServiceClientHelper <CourseEnrollments_ServiceClient, CourseEnrollments_Service>(Credentials, AppSettings);
                var service = genericServiceClientHelper.GetServiceClient();

                var navCourseEnrollments = new CourseEnrollments {
                    CourseEnrollment = courseEnrollments.ToArray()
                };

                CourseEnrollmentsRequest request = new CourseEnrollmentsRequest(navCourseEnrollments);
                var response = service.CourseEnrollmentsAsync(request);
                await service.CloseAsync();

                return(true);
            }
            catch (Exception exception)
            {
                throw new Exception($"Error in CreateCourseEnrollment(): {exception.Message}");
            }
        }
        public async Task <IActionResult> Edit(int id, [Bind("CourseID,StudentID")] CourseEnrollments courseEnrollments)
        {
            if (id != courseEnrollments.CourseID)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(courseEnrollments);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!CourseEnrollmentsExists(courseEnrollments.CourseID))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["CourseID"]  = new SelectList(_context.Courses, "ID", "ID", courseEnrollments.CourseID);
            ViewData["StudentID"] = new SelectList(_context.Student, "ID", "ID", courseEnrollments.StudentID);
            return(View(courseEnrollments));
        }
        public async Task <IActionResult> Create([Bind("CourseID,StudentID")] CourseEnrollments courseEnrollments)
        {
            if (ModelState.IsValid)
            {
                _context.Add(courseEnrollments);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["CourseID"]  = new SelectList(_context.Courses, "ID", "ID", courseEnrollments.CourseID);
            ViewData["StudentID"] = new SelectList(_context.Student, "ID", "ID", courseEnrollments.StudentID);
            return(View(courseEnrollments));
        }
예제 #4
0
 internal static bool CreateCourseEnrollment(IEnumerable <CourseEnrollment> courseEnrollments, ApiManagerCredentials credentials)
 {
     try
     {
         var navCourseEnrollments = new CourseEnrollments1 {
             CourseEnrollment = courseEnrollments.ToArray()
         };
         var courseCreateService = new CourseEnrollments
         {
             ApiCredentials = credentials
         };
         courseCreateService.CallCourseEnrollments(ref navCourseEnrollments);
         courseCreateService.Dispose();
         return(true);
     }
     catch (Exception exception)
     {
         Services.LogService.Error("Fejl i oprettelse af kursusister.", exception);
         return(false);
     }
 }