Beispiel #1
0
        public ActionResult Edit(PensumEditModel modelPensum)
        {
            bool   updateCourse = false;
            bool   updateGrade  = false;
            Pensum myPensum     = _pensumRepository.GetById(modelPensum.Id);

            if (myPensum.Grade.Id != modelPensum.IdGrade)
            {
                myPensum.Grade = _gradeRepository.GetById(modelPensum.IdGrade);
                updateGrade    = true;
            }
            if (myPensum.Course.Id != modelPensum.IdCourse)
            {
                myPensum.Course = _courseRepository.GetById(modelPensum.IdCourse);
                updateCourse    = true;
            }
            Pensum       pensum  = _pensumRepository.Update(myPensum, updateCourse, updateGrade);
            const string title   = "Pensum Actualizado";
            string       content = "El Pensum " + pensum.Id +
                                   " ha sido actualizado exitosamente.";

            TempData["MessageInfo"] = new MessageModel
            {
                Type    = "INFO",
                Title   = title,
                Content = content
            };
            return(RedirectToAction("Index"));
        }
        public ActionResult Edit(PensumEditModel modelPensum)
        {
            Pensum myPensum = _pensumRepository.GetById(modelPensum.Id);

            if (_pensumRepository.Filter(x => x.Grade.Id == myPensum.Grade.Id && x.Id != modelPensum.Id && x.Name.Equals(modelPensum.Name)).Any())
            {
                _viewMessageLogic.SetNewMessage("Error", "Ya existe un pensum con ese nombre.", ViewMessageType.ErrorMessage);
                return(RedirectToAction("Index", new { gradeId = myPensum.Grade.Id }));
            }
            myPensum = Mapper.Map(modelPensum, myPensum);
            Pensum       pensum  = _pensumRepository.Update(myPensum);
            const string title   = "Pensum Actualizado";
            string       content = "El Pensum " + pensum.Name +
                                   " ha sido actualizado exitosamente.";

            _viewMessageLogic.SetNewMessage(title, content, ViewMessageType.SuccessMessage);
            return(RedirectToAction("Index", new { gradeId = myPensum.Grade.Id }));
        }