Exemple #1
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();
            }
        }
Exemple #2
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"));
        }
Exemple #3
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);
        }
Exemple #4
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);
        }
Exemple #5
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()));
        }
Exemple #6
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;
                }
            }
        }
Exemple #7
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));
        }
        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);
        }