public async Task <IActionResult> Update([FromBody] EnrollmentVm request)
 {
     if (await _enrollmentService.Update(request))
     {
         return(Ok("Successfull"));
     }
     return(BadRequest("Trainee is in class"));
 }
        public async Task <EnrollmentVm> GetById(int classId, string traineeId)
        {
            var data = await _context.Enrollments.Where(x => x.ClassId == classId && x.TraineeId == traineeId)
                       .Include(x => x.Class).Include(x => x.Trainee).FirstOrDefaultAsync();

            EnrollmentVm vm = _mapper.Map <EnrollmentVm>(data);

            return(vm);
        }
Ejemplo n.º 3
0
        //RDLC Report for enrollment
        public ActionResult EnrollmentReport()
        {
            LocalReport localReport = new LocalReport();

            string path = Path.Combine(Server.MapPath("~/Reports"), "EnrollmentReport.rdlc");

            localReport.ReportPath = path;

            //list of data
            List <Enrollment> enrollments = new List <Enrollment>();

            enrollments = db.Enrollments.ToList();
            List <EnrollmentVm> enrollmentVm = new List <EnrollmentVm>();
            EnrollmentVm        enrollment;

            foreach (var item in enrollments)
            {
                enrollment = new EnrollmentVm
                {
                    CourseID     = item.Course.Title,
                    StudentID    = item.Student.FirstMidName + " " + item.Student.LastName,
                    EnrollmentID = item.EnrollmentID,
                    Grade        = item.Grade.ToString()
                };
                enrollmentVm.Add(enrollment);
            }
            //Dataset name. (rdlc dataset)
            ReportDataSource reportDataSource = new ReportDataSource("EnrollmentDataSet", enrollmentVm);

            string a = "Done";

            localReport.DataSources.Add(reportDataSource);

            List <Student> aStudents = db.Students.ToList();

            reportDataSource = new ReportDataSource("StdDataset", aStudents);
            localReport.DataSources.Add(reportDataSource);
            ReportParameter[] parameters = new ReportParameter[2];
            parameters[0] = new ReportParameter("SchoolName", a);
            parameters[1] = new ReportParameter("SectionName", "Section Name");

            localReport.SetParameters(parameters);
            //render to web/ anything else
            //Render() takes 7 parameters
            string mediaType, encoding, fileName;

            string[]  stringArray;
            Warning[] warnings;
            byte[]    dataByte = localReport.Render("PDF", null, out mediaType, out encoding, out fileName, out stringArray, out warnings);

            return(File(dataByte, mediaType));
        }
        public async Task <bool> Update(EnrollmentVm request)
        {
            var data = await _context.Enrollments.Where(x => x.ClassId == request.ClassId && x.TraineeId == request.TraineeId).FirstOrDefaultAsync();

            if (data == null)
            {
                return(false);
            }

            data.ClassId = request.ClassId;
            try
            {
                await _context.SaveChangesAsync();

                return(true);
            }
            catch
            {
                return(false);
            }
        }