示例#1
0
        public async Task <IActionResult> Attendance(List <GroupEnrollment> attendance, Guid?id, Guid?groupEnrollmentId)
        {
            ViewData["ParentId"] = id;

            if (ModelState.IsValid)
            {
                foreach (GroupEnrollment item in attendance)
                {
                    GroupEnrollment Exists_GroupEnrollment = await _context.GroupEnrollments.FindAsync(item.GroupEnrollmentId);

                    Exists_GroupEnrollment.Attendance            = item.Attendance;
                    Exists_GroupEnrollment.RefEnrollmentStatusId = item.RefEnrollmentStatusId;
                    Exists_GroupEnrollment.StatusDate            = DateTime.Now;
                }

                await _context.SaveChangesAsync();

                TempData["messageType"]  = "success";
                TempData["messageTitle"] = "RECORDS UPDATED";
                TempData["message"]      = "Records updated successfully";

                return(RedirectToAction("Index", new { id }));
            }

            return(View());
        }
示例#2
0
        public async Task <IActionResult> Create([Bind("GroupEnrollmentId,GroupId,ParticipantId,EnrollmentDate,Attendance,StatusDate,RefEnrollmentStatusId")] GroupEnrollment groupEnrollment)
        {
            if (ModelState.IsValid)
            {
                groupEnrollment.GroupEnrollmentId = Guid.NewGuid();
                _context.Add(groupEnrollment);
                await _context.SaveChangesAsync();

                TempData["messageType"]  = "success";
                TempData["messageTitle"] = "RECORD CREATED";
                TempData["message"]      = "New record successfully created";

                //return RedirectToAction(nameof(Index));
                return(RedirectToAction(nameof(Index), new { id = groupEnrollment.GroupId }));
            }
            ViewData["RefEnrollmentStatusId"] = new SelectList(_context.EnrollmentStatus, "EnrollmentStatusId", "EnrollmentStatus", groupEnrollment.RefEnrollmentStatusId);
            ViewData["GroupId"]       = new SelectList(_context.Groups, "GroupId", "GroupCode", groupEnrollment.GroupId);
            ViewData["ParticipantId"] = new SelectList(_context.Participants, "ParticipantId", "FirstName", groupEnrollment.ParticipantId);
            ViewData["ParentId"]      = groupEnrollment.GroupId;
            return(View(groupEnrollment));
        }
示例#3
0
        public async Task <IActionResult> Edit(Guid id, [Bind("GroupEnrollmentId,GroupId,ParticipantId,EnrollmentDate,Attendance,StatusDate,RefEnrollmentStatusId")] GroupEnrollment groupEnrollment)
        {
            if (id != groupEnrollment.GroupEnrollmentId)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(groupEnrollment);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!GroupEnrollmentExists(groupEnrollment.GroupEnrollmentId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }

                TempData["messageType"]  = "success";
                TempData["messageTitle"] = "RECORD UPDATED";
                TempData["message"]      = "Record successfully updated";

                //return RedirectToAction(nameof(Index));
                return(RedirectToAction(nameof(Index), new { id = groupEnrollment.GroupId }));
            }
            ViewData["RefEnrollmentStatusId"] = new SelectList(_context.EnrollmentStatus, "EnrollmentStatusId", "EnrollmentStatus", groupEnrollment.RefEnrollmentStatusId);
            ViewData["GroupId"]       = new SelectList(_context.Groups, "GroupId", "GroupCode", groupEnrollment.GroupId);
            ViewData["ParticipantId"] = new SelectList(_context.Participants, "ParticipantId", "FirstName", groupEnrollment.ParticipantId);
            ViewData["ParentId"]      = groupEnrollment.GroupId;
            return(View(groupEnrollment));
        }
        public async Task <IActionResult> Create(Guid?[] ParticipantId, DateTime?EnrollmentDate, Guid GroupId)
        //public async Task<IActionResult> Create([Bind("GroupEnrollmentId,GroupId,ParticipantId,EnrollmentDate,Attendance,StatusDate,RefEnrollmentStatusId")] GroupEnrollment groupEnrollment)
        {
            if (ModelState.IsValid)
            {
                var group = await _context.Groups
                            .Include(x => x.Programs)
                            .Where(x => x.GroupId == GroupId)
                            .FirstOrDefaultAsync();

                foreach (var item in ParticipantId)
                {
                    GroupEnrollment groupEnrollment = new GroupEnrollment
                    {
                        GroupEnrollmentId     = Guid.NewGuid(),
                        ParticipantId         = item.Value,
                        EnrollmentDate        = EnrollmentDate,
                        RefEnrollmentStatusId = 1,
                        GroupId = GroupId,
                    };
                    _context.Add(groupEnrollment);
                }

                await _context.SaveChangesAsync();

                TempData["messageType"]  = "success";
                TempData["messageTitle"] = "RECORD CREATED";
                TempData["message"]      = "New record successfully created";

                //return RedirectToAction(nameof(Index));
                return(RedirectToAction(nameof(Index), new { id = group.GroupId }));
            }
            //ViewData["RefEnrollmentStatusId"] = new SelectList(_context.EnrollmentStatus, "RefEnrollmentStatusId", "EnrollmentStatus", groupEnrollment.RefEnrollmentStatusId);
            //ViewData["GroupId"] = new SelectList(_context.Groups, "GroupId", "GroupCode", groupEnrollment.GroupId);
            //ViewData["ParticipantId"] = new SelectList(_context.Participants, "ParticipantId", "FirstName", groupEnrollment.ParticipantId);
            //ViewData["ParentId"] = groupEnrollment.GroupId;
            return(View());
        }
示例#5
0
        public async Task <IActionResult> Create(
            [Bind("ParticipantId,RegistrationDate,OrganizationId,RefParticipantTypeId,RefParticipantCohortId,ParticipantCode,FirstName,MiddleName,LastName,RefSexId,BirthDate,Age,Disability,RefStudentDisabilityTypeId,Phone,Mobile,Email,Facebook,InstantMessenger,RefLocationId,Address")] Participant participant,
            [Bind("ParticipantId,StudentCode,RefStudentTypeId,RefStudentSpecializationId,RefStudentYearOfStudyId,ParentGuardian")] Student student,
            [Bind("ParticipantId,RefTeacherTypeId,RefTeacherPositionId,RefTeacherEmploymentTypeId,GradeLevels")] Teacher teacher,
            [Bind("ParticipantId,RefEducationAdministratorTypeId,RefEducationAdministratorPositionId,RefEducationAdministratorOfficeId")] EducationAdministrator educationAdministrator,
            string[] RefLocationId,
            Guid?GroupId
            )
        {
            // Model Bindings for Student, Teacher, and Education Administrator are null if not included in POST.
            // Recommended to set to null before Model Validation if any property on these entities are required.
            if (ModelState.IsValid)
            {
                // *** RefLocation ***
                // Gets the last non-null item in RefLocationId array,
                // the array might have null values for locations left empty
                // and this assigns the last non-null location to RefLocationId
                if (RefLocationId.Length > 0)
                {
                    var location =
                        (from r in RefLocationId where !string.IsNullOrEmpty(r) select r)
                        .OrderByDescending(r => r).Count();

                    participant.RefLocationId = RefLocationId[location - 1];
                }

                // Participant
                participant.ParticipantId = Guid.NewGuid();
                _context.Add(participant);

                // Students
                if (participant.RefParticipantTypeId == 1)
                {
                    student.ParticipantId = participant.ParticipantId;
                    _context.Add(student);
                }
                // Teachers
                else if (participant.RefParticipantTypeId == 2)
                {
                    teacher.ParticipantId = participant.ParticipantId;
                    _context.Add(teacher);
                }
                // Education Administrators
                else if (participant.RefParticipantTypeId == 3)
                {
                    educationAdministrator.ParticipantId = participant.ParticipantId;
                    _context.Add(educationAdministrator);
                }

                // *** Create Group Enrollment and/or Group Evaluations ***
                // If Create action route includes GroupId parameter (from GroupEnrollment)
                // Creates GroupEnrollment record for this Participant
                if (GroupId != null)
                {
                    // Get related Group
                    var group = await _context.Groups
                                .Include(x => x.Programs)
                                .Where(x => x.GroupId == GroupId)
                                .FirstOrDefaultAsync();

                    // Create GroupEnrollment for this Participant
                    GroupEnrollment groupEnrollment = new GroupEnrollment
                    {
                        GroupEnrollmentId     = Guid.NewGuid(),
                        GroupId               = group.GroupId,
                        ParticipantId         = participant.ParticipantId,
                        RefEnrollmentStatusId = 1, //Status Enrolled
                        EnrollmentDate        = participant.RegistrationDate
                    };

                    _context.Add(groupEnrollment);

                    // If the Program selected for this Group has related ProgramAssessments
                    // Creates the GroupEvaluation records for each ProgramAssessment for this Participant
                    if (group.Programs.HasAssessment == true)
                    {
                        List <ProgramAssessment> programAssessments = new List <ProgramAssessment>();

                        // Get ProgramAssessments list related to this Group/Program
                        programAssessments = await _context.ProgramAssessments
                                             .Where(x => x.ProgramId == group.ProgramId)
                                             .ToListAsync();

                        if (programAssessments != null)
                        {
                            foreach (var assessment in programAssessments)
                            {
                                GroupEvaluation groupEvaluation = new GroupEvaluation
                                {
                                    GroupEvaluationId     = Guid.NewGuid(),
                                    GroupEnrollmentId     = groupEnrollment.GroupEnrollmentId,
                                    RefEvaluationStatusId = 1, // Status Enrolled
                                    ProgramAssessmentId   = assessment.ProgramAssessmentId,
                                };

                                _context.GroupEvaluations.Add(groupEvaluation);
                            }
                        }
                    }
                }

                await _context.SaveChangesAsync();

                TempData["messageType"]  = "success";
                TempData["messageTitle"] = "RECORD CREATED";
                TempData["message"]      = "New record successfully created";

                // If Action route includes GroupId redirect to GroupEnrollment
                if (GroupId != null)
                {
                    return(RedirectToAction(nameof(Index), "GroupEnrollments", new { id = GroupId }));
                }
                // Else redirect to Participants
                else
                {
                    return(RedirectToAction(nameof(Index)));
                }
            }

            // If Model NotValid return to Create View (Get)
            // If groupId is not null, Create a new participant and enroll to Group Enrollments
            if (GroupId != null)
            {
                var refOrganizationTypeId = await _context.Groups
                                            .Where(g => g.GroupId == GroupId)
                                            .Select(g => g.Organizations.RefOrganizationTypeId)
                                            .FirstOrDefaultAsync();

                // if School return OrganizationId for JSTree to pre-select Organization
                if (refOrganizationTypeId == 1)
                {
                    ViewData["OrganizationId"] = participant.OrganizationId;
                }

                ViewData["GroupId"] = GroupId;
            }
            // If groupId is null, Create new Participant only
            else
            {
                // return related organization Ids
            }

            // *** For JSTree ***
            //Logged User OrganizationId
            Guid?userOrganizacionId = (await _userManager.GetUserAsync(HttpContext.User))?.OrganizationId;

            if (userOrganizacionId == null)
            {
                return(NotFound());
            }

            //Get Logged User Organization
            var organization = await _context.Organizations
                               .SingleOrDefaultAsync(o => o.OrganizationId == userOrganizacionId);

            if (organization == null)
            {
                return(NotFound());
            }

            //Returns the top hiearchy organization for JSTree
            ViewData["ParentOrganizationId"] = organization.OrganizationId;

            // *** Select Lists ***
            // RefLocation
            var locationTypes = _context.LocationTypes;

            ViewData["RefLocationTypes"]      = locationTypes;
            ViewData["RefLocationTypesCount"] = locationTypes.Count();

            ViewData["RefLocationId"] = new SelectList(_context.Locations
                                                       .Include(x => x.LocationTypes)
                                                       .Where(x =>
                                                              x.LocationTypes.LocationLevel == 1 &&
                                                              x.ParentLocationId == null)
                                                       .Select(x => new
            {
                x.RefLocationId,
                x.LocationName
            }), "RefLocationId", "LocationName");

            // Participants - All
            ViewData["ParentId"]               = participant.OrganizationId;
            ViewData["RefSexId"]               = new SelectList(_context.Sex, "RefSexId", "Sex");
            ViewData["RefDisabilityTypeId"]    = new SelectList(_context.DisabilityTypes, "RefDisabilityTypeId", "DisabilityType");
            ViewData["RefParticipantTypeId"]   = participant.RefParticipantTypeId;
            ViewData["RefParticipantCohortId"] = new SelectList(_context.ParticipantCohorts, "RefParticipantCohortId", "ParticipantCohort");

            // Students
            if (participant.RefParticipantTypeId == 1)
            {
                ViewData["RefStudentTypeId"]           = new SelectList(_context.StudentTypes, "RefStudentTypeId", "StudentType", student.RefStudentTypeId);
                ViewData["RefStudentSpecializationId"] = new SelectList(_context.StudentSpecializations, "RefStudentSpecializationId", "StudentSpecialization", student.RefStudentSpecializationId);
                ViewData["RefStudentYearOfStudyId"]    = new SelectList(_context.StudentYearOfStudies, "RefStudentYearOfStudyId", "StudentYearOfStudy");
            }
            // Teachers
            else if (participant.RefParticipantTypeId == 2)
            {
                ViewData["RefTeacherTypeId"]           = new SelectList(_context.TeacherTypes, "RefTeacherTypeId", "TeacherType", teacher.RefTeacherTypeId);
                ViewData["RefTeacherPositionId"]       = new SelectList(_context.TeacherPositions, "RefTeacherPositionId", "TeacherPosition", teacher.RefTeacherPositionId);
                ViewData["RefTeacherEmploymentTypeId"] = new SelectList(_context.TeacherEmploymentTypes, "RefTeacherEmploymentTypeId", "TeacherEmploymentType");
            }
            // Education Administrators
            else if (participant.RefParticipantTypeId == 3)
            {
                ViewData["RefEducationAdministratorTypeId"]     = new SelectList(_context.EducationAdministratorTypes, "RefEducationAdministratorTypeId", "EducationAdministratorType", educationAdministrator.RefEducationAdministratorTypeId);
                ViewData["RefEducationAdministratorOfficeId"]   = new SelectList(_context.EducationAdministratorOffices, "RefEducationAdministratorOfficeId", "EducationAdministratorOffice", educationAdministrator.RefEducationAdministratorPositionId);
                ViewData["RefEducationAdministratorPositionId"] = new SelectList(_context.EducationAdministratorPositions, "RefEducationAdministratorPositionId", "EducationAdministratorPosition", educationAdministrator.RefEducationAdministratorPositionId);
            }

            return(RedirectToAction(nameof(Create), "Participants", new { participant.OrganizationId, GroupId, participant.RefParticipantTypeId }));
        }