public ActionResult Edit(int id)
        {
            var cl = repo.GetById(id);

            if (cl == null)
            {
                return(HttpNotFound());
            }

            try
            {
                var cls = CompleteClass();

                cls.Title          = cl.Title;
                cls.Description    = cl.Description;
                cls.Price          = cl.Price;
                cls.PosterSrc      = cl.PosterSrc;
                cls.CategoryId     = cl.CategoryId;
                cls.LevelId        = cl.LevelId;
                cls.Requirements   = cl.Requirements;
                cls.TargetStudents = cl.TargetStudents;
                cls.TypeId         = cl.TypeId;
                cls.ClassId        = cl.ClassId;
                cls.DateCreated    = cl.DateCreated;

                return(View(cls));
            }
            catch
            {
                return(RedirectToAction("Index", "Home"));
            }
        }
示例#2
0
        public IHttpActionResult Get(int id)
        {
            var result = classRepo.GetById(id);

            if (result == null)
            {
                return(Content(HttpStatusCode.NotFound, "Item does not exist"));
            }
            return(Ok(result));
        }
        public void UpdateClass()
        {
            ClassRepository repo = new ClassRepository(new ClassSQLContext());
            Class           c    = repo.GetById(2);

            c.PhysDamage += 20;
            int damage = c.PhysDamage;

            repo.Update(c);
            c = repo.GetById(2);
            Assert.AreEqual(c.PhysDamage, damage, "Class wasn't updated.");
            c.PhysDamage -= 20;
            repo.Update(c);
        }
示例#4
0
        public ActionResult Edit(Guid id)
        {
            var classRepository = new ClassRepository(_context);
            var klass           = classRepository.GetById(id);
            var userRole        = GetUserRole(_loggedUser);

            if ((Role.Teacher != userRole ||
                 klass.Teacher.Id != _loggedUser.Id && klass.Course.TeacherInCharge.Id != _loggedUser.Id) &&
                userRole != Role.Admin)
            {
                return(RedirectToAction("Index", "Home"));
            }


            var courseRepository = new CourseRepository(_context);
            var activeCourses    = courseRepository.ListActiveCourses();

            ViewBag.Courses = new SelectList(activeCourses, "Id", "Name");

            var userRepository = new UserRepository(_context);
            var activeTeachers = userRepository.ListActiveTeachers();

            ViewBag.Teachers = new SelectList(activeTeachers, "Id", "Name");
            const ContentType contentType = ContentType.Vimeo;

            ViewBag.ContentTypes = new SelectList(contentType.ToDataSource <ContentType>(), "Key", "Value");

            return(View(ClassViewModel.FromEntity(klass, 0, new DefaultDateTimeHumanizeStrategy())));
        }
示例#5
0
        public ActionResult SaveSupportMaterial(string id)
        {
            using (var tx = new TransactionScope())
            {
                var uploader     = new SupportMaterialUploader(id);
                var uploadResult = uploader.Upload(Request.Files[0]);

                var classRepository = new ClassRepository(_context);
                var klass           = classRepository.GetById(new Guid(id));

                klass.Files.Add(new File
                {
                    PhysicalPath = uploadResult.Message,
                    CreatedAt    = DateTime.Now,
                    Active       = true,
                    Name         = Request.Files[0]?.FileName,
                    Class        = klass
                });

                _context.Save(_loggedUser);

                tx.Complete();
                return(Json(uploadResult));
            }
        }
        public void ClassSelect()
        {
            ClassRepository repo = new ClassRepository(new ClassSQLContext());
            Class           c    = repo.GetById(1);

            Assert.IsNotNull(c, "Class wasn't correctly retrieved");
        }
        public ActionResult Edit(int id)
        {
            // Get the existing class.
            var @class = _classRepository.GetById(id);

            if (@class == null)
            {
                // Class does not exists, show the overview page.
                return(RedirectToAction("List"));
            }

            // Map the class to a view model.
            var model = Mapper.Map <ClassModel>(@class);

            PrepareClassModel(model);
            return(View(model));
        }
示例#8
0
        public void Handles(StudentEnrollCommand command)
        {
            var student = _studentRepository.GetById(command.StudentId);
            var @class  = _classRepository.GetById(command.ClassId);

            try
            {
                student.TryEnrollIn(@class);
                @class.TryEnroll(student);

                student.Enroll(@class);
                @class.Enroll(student);
            }
            catch (Exception e)
            {
                // log
            }
        }
        public ActionResult AppointmentByStudent(AppointmentByStudentModel model)
        {
            // A student wishes to make an appointment with their counseler.
            if (ModelState.IsValid)
            {
                // Get the logged in student and counseler of the class the student is in.
                var student   = Student;
                var @class    = _classRepository.GetById(student.ClassId);
                var counseler = CounselerRepository.GetById(@class.CounselerId);

                if (counseler != null && student != null)
                {
                    // Create the appointment for the student and couseler.
                    var appointment = new Appointment
                    {
                        CounselerId = counseler.Id,
                        StudentId   = student.Id,
                        DateTime    = model.DateTime,
                        Location    = model.Location
                    };

                    int id = _appointmentRepository.Add(appointment);

                    // Send the appointment request mail.
                    var mail = new AppointmentMail
                    {
                        Counseler     = counseler,
                        Student       = student,
                        DateTime      = appointment.DateTime,
                        Location      = appointment.Location,
                        AcceptUrl     = FullUrl("AppointmentResponse", new { id }),
                        FromCounseler = false
                    };

                    _mailHelper.SendAppointmentMail(mail);

                    return(RedirectToAction("Details", "Appointment", new { id }));
                }
            }

            PrepareStudentCounselingRequestModel(model);
            return(View(model));
        }
示例#10
0
        public void Unroll(StudentRepository studentRepository, ClassRepository classRepository,
                           StudentArchiveRepository studentArchiveRepository, StudentUnrollCommand command)
        {
            var student        = studentRepository.GetById(command.StudentId);
            var @class         = classRepository.GetById(command.ClassId);
            var studentArchive = studentArchiveRepository.GetById(command.StudentId);

            student.Unroll(@class);
            @class.Unroll(student);
            studentArchive.AddToPassedEnrollements(student.LastUnrolled, command.Reason);
        }
示例#11
0
        public void Enroll(StudentRepository studentRepository, ClassRepository classRepository,
                           StudentEnrollCommand command)
        {
            var student = studentRepository.GetById(command.StudentId);
            var @class  = classRepository.GetById(command.ClassId);

            student.TryEnrollIn(@class);
            @class.TryEnroll(student);

            student.Enroll(@class);
            @class.Enroll(student);
        }
示例#12
0
        public void Handles(StudentEnrollCommand command)
        {
            var student = _studentRepository.GetById(command.StudentId);
            var @class  = _classRepository.GetById(command.ClassId);

            try
            {
                _unitOfWork.BeginTransaction();
                student.TryEnrollIn(@class);
                @class.TryEnroll(student);

                student.Enroll(@class);
                @class.Enroll(student);
                _notificationService.Notify(student);
                _unitOfWork.Commit();
            }
            catch (Exception e)
            {
                _logger.LogError(e);
            }
        }
示例#13
0
        public void Get_class_by_id_test()
        {
            var repo   = new ClassRepository(context);
            var model  = new ClassEntity("GR2");
            var model2 = new ClassEntity("GR1");

            repo.AddNew(model);
            repo.AddNew(model2);
            var result = repo.GetById(model2.Id);

            Assert.IsNotNull(result);
            Assert.AreEqual(result.Id, model2.Id);
        }
示例#14
0
        public ActionResult ListSupportMaterial(string classId)
        {
            var classRepository = new ClassRepository(_context);
            var klass           = classRepository.GetById(new Guid(classId));

            var files    = new List <dynamic>();
            var uploader = new SupportMaterialUploader(classId);

            foreach (var item in klass.Files)
            {
                files.Add(new
                {
                    item.Name,
                    Size = uploader.GetFileInfo(item.PhysicalPath).Length
                });
            }

            return(Json(new { Files = files }));
        }
示例#15
0
        public ActionResult DeleteSupportMaterial(string id, string fileName)
        {
            using (var tx = new TransactionScope())
            {
                var classRepository = new ClassRepository(_context);
                var klass           = classRepository.GetById(new Guid(id));
                var file            = klass.Files.Single(x => x.PhysicalPath == fileName);
                klass.Files.Remove(file);
                classRepository.UpdateWithFiles(klass);
                _context.Save(_loggedUser);

                var uploader = new SupportMaterialUploader(id);
                uploader.DeleteFile(fileName);

                tx.Complete();
            }

            return(new HttpStatusCodeResult(HttpStatusCode.OK));
        }
示例#16
0
        public ActionResult Delete(string id)
        {
            var classRepository = new ClassRepository(_context);
            var uploader        = new SupportMaterialUploader(id);
            var klass           = classRepository.GetById(new Guid(id));

            using (var tx = new TransactionScope())
            {
                foreach (var file in klass.Files)
                {
                    uploader.DeleteFile(file.PhysicalPath);
                }

                classRepository.Delete(klass.Id);
                _context.Save(_loggedUser);

                tx.Complete();
            }

            return(new HttpStatusCodeResult(HttpStatusCode.OK));
        }