Example #1
0
        public IActionResult SaveSubject(SubjectModel subjectModel)
        {
            if (!ModelState.IsValid)
            {
                return(Content(UiMessages.WrongMessage));
            }

            SubjectMapper subjectMapper = new SubjectMapper();
            Subject       subject       = subjectMapper.Map(subjectModel);

            subject.Creator = CurrentUser;

            if (subject.ID != 0)
            {
                DB.SubjectRepository.Update(subject);
                TempData["Message"] = UiMessages.SuccesMessage;
            }
            else
            {
                DB.SubjectRepository.Add(subject);
                TempData["Message"] = UiMessages.SuccesMessage;
            }

            return(RedirectToAction("Index"));
        }
Example #2
0
        [TestCase("PCET ESOL", "further education, english as a second or other language", "Further education")]                              // secondary ESOL

        public void MapToSearchAndCompareCourse(string courseTitle, string commaSeparatedUcasSubjects, string commaSeparatedExpectedSubjects)
        {
            var expected = commaSeparatedExpectedSubjects.Split(", ");
            var result   = new SubjectMapper().GetSubjectList(courseTitle, commaSeparatedUcasSubjects.Split(", "));

            result.Should().BeEquivalentTo(expected);
        }
Example #3
0
        public override void Execute(object parameter)
        {
            SureDialogViewModel sureViewModel = new SureDialogViewModel();

            sureViewModel.DialogText = UIMessages.DeleteSureMessage;

            SureDialog dialog = new SureDialog();

            dialog.DataContext = sureViewModel;
            dialog.ShowDialog();

            if (dialog.DialogResult == true)
            {
                SubjectMapper mapper = new SubjectMapper();

                Subject subject = mapper.Map(viewModel.CurrentSubject);
                subject.IsDeleted = true;
                subject.Creator   = Kernel.CurrentUser;

                DB.SubjectRepository.Update(subject);

                int no = viewModel.SelectedSubject.No;

                viewModel.CurrentSituation = (int)Situation.NORMAL;
                viewModel.Subjects.Remove(viewModel.SelectedSubject);

                List <SubjectModel> modelList = viewModel.Subjects.ToList();
                EnumerationUtil.Enumerate(modelList, no - 1);
                viewModel.AllSubjects = modelList;
                viewModel.UpdateDataFiltered();

                viewModel.SelectedSubject = null;
                viewModel.CurrentSubject  = new SubjectModel();
            }
        }
Example #4
0
        /// <summary>
        ///     Crea una nueva asignatura
        /// </summary>
        /// <param name="subject">
        ///     Un objeto Subject que contiene los datos de la asignatura
        /// </param>
        /// <exception cref="SubjectNameDuplicateEntryException">
        ///     Lanza SubjectNameDuplicateEntryException
        /// </exception>
        /// <returns>
        ///     El objeto Subject creado con el id generado
        /// </returns>
        public async Task <Subject> Save(Subject subject)//throw SubjectNameDuplicateEntryException
        {
            SubjectEntity subjectEntity = SubjectMapper.Map(subject);

            subjectEntity = await _subjectRepository.Save(subjectEntity);

            subject = SubjectMapper.Map(subjectEntity);

            return(subject);
        }
Example #5
0
        /// <summary>
        ///     Actualiza una asignatura
        /// </summary>
        /// <param name="subject">
        ///     Un objeto Subject que contiene los nuevos datos de la asignatura
        /// </param>
        /// <exception cref="SubjectNameDuplicateEntryException">
        ///     Lanza SubjectNameDuplicateEntryException
        /// </exception>
        /// <returns>
        ///     El objeto Subject actualizado
        /// </returns>
        public async Task <Subject> Update(Subject subject)
        {
            SubjectEntity subjectEntity = SubjectMapper.Map(subject);

            subjectEntity = await _subjectRepository.Update(subjectEntity);

            subject = SubjectMapper.Map(subjectEntity);

            return(subject);
        }
Example #6
0
        /// <summary>
        ///     Lista todas las asignaturas de un curso
        /// </summary>
        /// <param name="courseId">
        ///     El id del curso
        /// </param>
        /// <returns>
        ///     Retorna una lista de objetos Subject
        /// </returns>
        public async Task <List <Subject> > GetByCourse(int courseId)
        {
            List <SubjectEntity> subjectEntities = await _subjectRepository
                                                   .GetByCourseIncludingAssignedTeacher(courseId);

            List <Subject> subjects = subjectEntities
                                      .Select(s => SubjectMapper.MapIncludingTeacher(s))
                                      .ToList();

            return(subjects);
        }
Example #7
0
        /// <summary>
        ///     Cambia el profesor asignado a una asignatura
        /// </summary>
        /// <param name="subjectId">
        ///     El id de la asignatura
        /// </param>
        /// <param name="teacherId">
        ///     El id del profesor
        /// </param>
        /// <returns>
        ///     Retorna el objeto asignatura que contiene
        ///     el nuevo objeto Teacher asignado
        /// </returns>
        public async Task <Subject> UpdateAssignedTeacher(int subjectId, int teacherId)
        {
            TeacherEntity teacherEntity = await _teachertRepository.Get(teacherId);

            SubjectEntity subjectEntity = await _subjectRepository
                                          .UpdateAssignedTeacher(subjectId, teacherEntity);

            Subject subject = SubjectMapper.MapIncludingTeacher(subjectEntity);

            return(subject);
        }
Example #8
0
        public PageOperationResponse <SubjectMessage> Read(SubjectFilter filter)
        {
            PageOperationResponse <SubjectMessage> response = null;

            try
            {
                var model = this.entityService.Read(filter);
                response = SubjectMapper.MapTo(model);
            }
            catch (Exception ex)
            {
                response = base.CreatePageErrorResponse <SubjectMessage>(ex, filter.Protocol, OperationStatusType.SystemError);
            }

            return(response);
        }
Example #9
0
        public IActionResult SaveSubject(int ID)
        {
            if (ID != 0)
            {
                Subject subject = DB.SubjectRepository.Get(ID);

                if (subject == null)
                {
                    return(Content("Fənn Tapılmadı"));
                }

                SubjectMapper subjectMapper = new SubjectMapper();
                SubjectModel  subjectModel  = subjectMapper.Map(subject);

                return(View(subjectModel));
            }
            return(View(new SubjectModel()));
        }
Example #10
0
        public override void Execute(object parameter)
        {
            if (viewModel.CurrentSituation == (int)Situation.NORMAL)
            {
                viewModel.CurrentSituation = (int)Situation.ADD;
            }
            else if (viewModel.CurrentSituation == (int)Situation.SELECTED)
            {
                viewModel.CurrentSituation = (int)Situation.EDIT;
            }
            else
            {
                if ((viewModel.CurrentSituation == (int)Situation.ADD) || viewModel.CurrentSituation == (int)Situation.EDIT)
                {
                    SubjectMapper subjectMapper = new SubjectMapper();
                    Subject       subject       = subjectMapper.Map(viewModel.CurrentSubject);

                    subject.Creator = Kernel.CurrentUser;
                    if (subject.ID != 0)
                    {
                        DB.SubjectRepository.Update(subject);

                        SubjectModel updatedModel = viewModel.AllSubjects.FirstOrDefault(x => x.ID == viewModel.CurrentSubject.ID);
                        int          updatedIndex = viewModel.AllSubjects.IndexOf(updatedModel);

                        viewModel.AllSubjects[updatedIndex] = viewModel.CurrentSubject;
                    }
                    else
                    {
                        viewModel.CurrentSubject.ID = DB.SubjectRepository.Add(subject);
                        viewModel.CurrentSubject.No = viewModel.Subjects.Count + 1;

                        viewModel.AllSubjects.Add(viewModel.CurrentSubject);
                    }

                    viewModel.UpdateDataFiltered();

                    viewModel.SelectedSubject  = null;
                    viewModel.CurrentSubject   = new SubjectModel();
                    viewModel.CurrentSituation = (int)Situation.NORMAL;
                }
            }
        }
Example #11
0
        public IActionResult Index()
        {
            ViewBag.Message = TempData["Message"];

            List <Subject> subjects = DB.SubjectRepository.Get();

            SubjectViewModel subjectViewModel = new SubjectViewModel();

            SubjectMapper subjectMapper = new SubjectMapper();

            foreach (var subject in subjects)
            {
                var subjectModel = subjectMapper.Map(subject);
                subjectViewModel.Subjects.Add(subjectModel);
            }

            EnumerationUtil.Enumerate(subjectViewModel.Subjects);

            return(View(subjectViewModel));
        }
Example #12
0
 public static bool SubjectAdd(string Name, bool IsLecture)
 {
     if (!HasSubjectName(Name))
     {
         using (var context = new Classmaister5000Entities())
         {
             SubjectModel newSubject = new SubjectModel();
             newSubject.SubjectName = Name;
             newSubject.IsLecture   = IsLecture;
             newSubject.User_Id     = GetUserId;
             context.Subjects.Add(SubjectMapper.ModelToEntity(newSubject));
             context.SaveChanges();
             return(true);
         }
     }
     else
     {
         throw new SubjectAlreadyExistsException();
     }
 }
Example #13
0
        public static List <SubjectModel> GetSubjects()
        {
            List <Subject>      subjects      = Kernel.DB.SubjectRepository.Get();
            List <SubjectModel> subjectModels = new List <SubjectModel>();

            SubjectMapper mapper = new SubjectMapper();

            foreach (var subject in subjects)
            {
                SubjectModel subjectModel = mapper.Map(subject);
                subjectModels.Add(subjectModel);
            }

            //for (int i = 0; i < subjects.Count; i++)
            //{
            //    Subject subject = subjects[i];
            //    SubjectModel model = mapper.Map(subject);
            //    model.No = i + 1;
            //    subjectModels.Add(model);
            //}
            return(subjectModels);
        }
Example #14
0
 public async Task <Subject> FindBySubjectNameAndCodeAsync(string name, string code)
 {
     return(SubjectMapper.MapFromInternal(await Uow.Subjects.FindBySubjectNameAndCodeAsync(name, code)));
 }
Example #15
0
 public async Task <Subject> FindBySubjectNameAndCodeAsync(string name, string code)
 {
     return(SubjectMapper.MapFromDomain(await RepositoryDbSet
                                        .AsNoTracking()
                                        .FirstOrDefaultAsync(s => s.SubjectName == name && s.SubjectCode == code)));
 }
Example #16
0
 public SubjectController(SubjectMapper mapper, SubjectService service)
     : base(mapper, service)
 {
 }