Ejemplo n.º 1
0
        public Enrolment CreateEnrolment(CourseDelivery course)
        {
            var result = new Enrolment(this, course);

            Enrolments.Add(result);
            foreach (var subject in result.CourseRun.Subjects)
            {
                Attendance.Add(subject.Name, new List <Attendance>());
            }
            course.Enrolments.Add(result);
            return(result);
        }
Ejemplo n.º 2
0
        public async Task Delete(EnrolmentUpdate enrolment)
        {
            ValidationErrors = null;
            try
            {
                await _enrolmentService.Delete(enrolment.Id);

                Enrolments.RowEditOptions.EditRowId = null;
                Enrolments.RequestRefresh();
            }
            catch (ValidationException ve)
            {
                ValidationErrors = ve.Errors.ToList();
            }
        }
Ejemplo n.º 3
0
        public override async Task PreRender()
        {
            if (Enrolments.IsRefreshRequired)
            {
                var enrolmentsList = (await _enrolmentService.GetUpdateable()).Select(_ => new EnrolmentUpdateListModel
                {
                    Id               = _.Id,
                    Course           = _.Course,
                    Enrolment        = _.Enrolment,
                    Semester         = _.Semester,
                    Student          = _.Student,
                    GradeDescription = _.Enrolment.FinalGrade.GetEnumDescription()
                });

                Enrolments.LoadFromQueryable(enrolmentsList.AsQueryable());
            }

            await base.PreRender();
        }
Ejemplo n.º 4
0
        public async Task SaveEdit(EnrolmentUpdate enrolment)
        {
            ValidationErrors = null;
            try
            {
                await _enrolmentService.Update(enrolment.Id, enrolment);

                Enrolments.RowEditOptions.EditRowId = null;
                Enrolments.RequestRefresh();
            }
            catch (ValidationPropertyException vpe)
            {
                ValidationErrors = vpe.ErrorsList.ToList();
            }
            catch (ValidationException ve)
            {
                ValidationErrors = ve.Errors.ToList();
            }
        }
Ejemplo n.º 5
0
        public async Task ForceSave()
        {
            ValidationErrors = null;
            try
            {
                await _enrolmentService.UpdateAndCreate(NewEnrolments.Select(_ => _.Enrolment).ToList());

                Enrolments.RequestRefresh();
                NewEnrolments = null;
                CreateMode    = false;
                Enrolments.RowEditOptions.EditRowId = null;
            }
            catch (ValidationPropertyException vpe)
            {
                ValidationErrors = vpe.ErrorsList.ToList();
            }
            catch (ValidationException ve)
            {
                ValidationErrors = ve.Errors.ToList();
            }
        }
Ejemplo n.º 6
0
 public void AddSubject(Subject subject)
 {
     Enrolments.Add(subject);
 }
Ejemplo n.º 7
0
        private void NavigateEnrolments_Click(object sender, RoutedEventArgs e)
        {
            var page = new Enrolments(_enrolmentService, _courseService, _studentService);

            MainContent.Navigate(page);
        }
Ejemplo n.º 8
0
 public List <Enrolment> GetActiveEnrolments()
 {
     return(Enrolments.Where(e => e.CourseRun.DeliveryPeriod.End >= DateTime.Now).ToList());
 }
Ejemplo n.º 9
0
 public void CancelEdit()
 {
     Enrolments.RowEditOptions.EditRowId = null;
     Enrolments.RequestRefresh();
 }
        public AuthzResponse Authz([FromQuery] string serviceid, [FromQuery] string b2cobjectid)
        {
            List <string> rolesList    = new List <string>();
            List <string> mappingsList = new List <string>();

            try
            {
                // Client Mutual Authentication
                string authenicationResult = AuthenticateCertificate();

                // If there are error for Client Certificate checks return 403
                if (!string.IsNullOrEmpty(authenicationResult))
                {
                    return(new AuthzResponse
                    {
                        status = (int)HttpStatusCode.Forbidden,
                        message = $"Access Denied - {authenicationResult}",
                        version = ApiVersion.Default.ToString(),
                        roles = rolesList,
                        mappings = mappingsList,
                    });
                }

                // B2C Object ID validation
                if (string.IsNullOrEmpty(b2cobjectid) ||
                    !Guid.TryParse(b2cobjectid, out Guid b2cobjectIdGuid))
                {
                    return(new AuthzResponse
                    {
                        status = (int)HttpStatusCode.BadRequest,
                        message = "B2CObjectId is invalid, is not a valid Guid.",
                        version = ApiVersion.Default.ToString(),
                        roles = rolesList,
                        mappings = mappingsList,
                    });
                }

                // Service ID validation
                if (string.IsNullOrEmpty(serviceid) ||
                    !Guid.TryParse(serviceid, out Guid serviceIdGuid))
                {
                    return(new AuthzResponse
                    {
                        status = (int)HttpStatusCode.BadRequest,
                        message = "ServiceId is invalid, is not a valid Guid.",
                        version = ApiVersion.Default.ToString(),
                        roles = rolesList,
                        mappings = mappingsList,
                    });
                }

                // Make Authorisation request
                Enrolments enrolments = CrmWrapper.Authz(serviceIdGuid, b2cobjectIdGuid);

                // If no Enrolments return No Content
                if (enrolments?.ServiceUserLinks?.Count == 0)
                {
                    return(new AuthzResponse
                    {
                        status = (int)HttpStatusCode.NoContent,
                        message = "No Content",
                        version = ApiVersion.Default.ToString(),
                        roles = rolesList,
                        mappings = mappingsList,
                    });
                }

                // Compile return JSON, used for loop because of performance
                for (int i = 0; i < enrolments.ServiceUserLinks.Count; i++)
                {
                    ServiceUserLink serviceUserLink = enrolments.ServiceUserLinks[i];
                    string          roleListItem    = $"{serviceUserLink.OrganisationId}:{serviceUserLink.RoleId}:{serviceUserLink.EnrolmentStatus}";
                    if (!rolesList.Contains(roleListItem))
                    {
                        rolesList.Add(roleListItem);
                    }

                    string mappingListOrgItem = $"{serviceUserLink.OrganisationId}:{serviceUserLink.OrganisationName}";
                    if (!mappingsList.Contains(mappingListOrgItem))
                    {
                        mappingsList.Add(mappingListOrgItem);
                    }

                    string mappingListRoleItem = $"{serviceUserLink.RoleId}:{serviceUserLink.RoleName}";
                    if (!mappingsList.Contains(mappingListRoleItem))
                    {
                        mappingsList.Add(mappingListRoleItem);
                    }

                    string mappingListStatus = $"{serviceUserLink.EnrolmentStatus}:{serviceUserLink.EnrolmentStatusText}";
                    if (!mappingsList.Contains(mappingListStatus))
                    {
                        mappingsList.Add(mappingListStatus);
                    }
                }
            }
            catch (WebFaultException ex)
            {
                System.Diagnostics.Trace.TraceError(ex.Message);
                return(new AuthzResponse
                {
                    status = ex.HttpStatusCode,
                    message = ex.ErrorMsg + " " + ex.InnerException?.Message,
                    version = ApiVersion.Default.ToString(),
                    roles = rolesList,
                    mappings = mappingsList
                });
            }
            catch (Exception ex)
            {
                System.Diagnostics.Trace.TraceError(ex.Message);
                return(new AuthzResponse
                {
                    status = (int)HttpStatusCode.InternalServerError,
                    message = ex.Message,
                    version = ApiVersion.Default.ToString(),
                    roles = rolesList,
                    mappings = mappingsList,
                });
            }

            return(new AuthzResponse
            {
                status = (int)HttpStatusCode.OK,
                message = "Success!",
                version = ApiVersion.Default.ToString(),
                roles = rolesList,
                mappings = mappingsList,
            });
        }