public ActionResult Create(CreateSubjectFormViewModel Model)
        {
            _DynamicModalOptions = new DynamicModalOptions
            {
                Title      = "Create Subject",
                FormMethod = FormMethod.Post,
                FormType   = FormType.Create
            };

            if (!ModelState.IsValid)
            {
                return(ViewModal(Model, _DynamicModalOptions));
            }

            SubjectModel Subject = Model.ToSubjectModel(_SubjectService.GetSubjects().Where(x => x.Removed == null).ToList());

            if (_SubjectService.GetSubject(Subject.Code) != null)
            {
                return(ViewModal(Model, _DynamicModalOptions));
            }

            try
            {
                _SubjectService.CreateSubject(Subject);
                _SubjectService.SaveSubject();

                return(ModalMessage("Dialog Message", "Subject created successfully"));
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
                return(ModalMessage("Dialog Message", "Something went wrong"));
            }
        }
Example #2
0
        public static CreateSubjectFormViewModel ToCreateSubjectFormViewModel(this SubjectModel Model, ICollection <SubjectModel> Subjects)
        {
            CreateSubjectFormViewModel ViewModel = new CreateSubjectFormViewModel();

            ViewModel             = Mapper.Map <SubjectModel, CreateSubjectFormViewModel>(Model);
            ViewModel.AllSubjects = Subjects.ToList();
            return(ViewModel);
        }
Example #3
0
        public static SubjectModel ToSubjectModel(this CreateSubjectFormViewModel ViewModel, ICollection <SubjectModel> Subjects)
        {
            SubjectModel Model = new SubjectModel();

            Model = Mapper.Map <CreateSubjectFormViewModel, SubjectModel>(ViewModel);
            ViewModel.PrerequisiteIDs.ToList().ForEach(ID => Model.Prerequisites.Add(Subjects.FirstOrDefault(x => x.ID == ID)));
            return(Model);
        }