Example #1
0
        public IActionResult Guardar(TeacherModel model)
        {
            try
            {
                var data = CopyPropierties.Convert <TeacherModel, Teacher>(model);
                _teacher.Save(data);
            }
            catch (Exception e)
            {
                //var model = CopyPropierties.Convert<Teacher, TeacherModel>(data);
                //ViewBag.ContactTypes = new SelectList(_contactType.GetAll, "ContactTypeId", "ContactTypeName");
                //ViewBag.DocumentType = new SelectList(_documentType.GetAll, "DocumentTypeId", "DocumentTypeName");
                //ViewBag.Countries = new SelectList(_country.Country, "CountryId", "CountryName");
                //ViewBag.Cities = new SelectList(_country.Country, "CityId", "CityName");
                //ViewBag.AddressTypes = new SelectList(_addressType.addressTypes, "AddressTypeId", "AddressTypeName");
                ////ViewBag.Status = new SelectList(_status);
                //ViewBag.EducationType = new SelectList(_educationType.GetAll, "EducationTypeId", "EducationTypeName");
                //ViewBag.TeacherEducation = new SelectList(_teacherEducation.GetAll, "TeacherEducationId", "TeacherEducationTitle");
                //ViewBag.Nationality = new SelectList(_nationality.GetAll, "NationalityId", "NationalityName");
                //ViewBag.MatirialStatus = new SelectList(_matirialStatus.GetAll, "MaritalStatusId", "MaritalStatusName");

                //return View("Crear", model);
            }


            return(View("Index", _teacher.GetAll));
        }
Example #2
0
        public IActionResult GuardarTeacher(TeacherModel model)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    var data = CopyPropierties.Convert <TeacherModel, Teacher>(model);
                    data.Contact.ContactName           = model.Name;
                    data.Contact.ContactLastname       = model.LastName;
                    data.Contact.ContactDocumentNumber = model.Document;
                    data.Contact.Nationality           = model.Nacionality;
                    _teacher.Save(data);
                }
                catch (Exception e)
                {
                    return(RedirectToAction("Editar", new { id = model.TeacherId }));
                }
            }
            else
            {
                var errors = ModelState.Select(x => x.Value.Errors).FirstOrDefault(x => x.Count > 0).First();



                EnviarMensaje.Enviar(TempData, "red", errors.ErrorMessage);


                if (model.TeacherId != null)
                {
                    return(RedirectToAction("Editar", new { id = model.TeacherId }));
                }


                ViewBag.ContactTypes      = new SelectList(_contactType.GetAll, "ContactTypeId", "ContactTypeName");
                ViewBag.DocumentType      = new SelectList(_documentType.GetAll, "DocumentTypeId", "DocumentTypeName");
                ViewBag.Countries         = new SelectList(_country.GetAll, "CountryId", "CountryName");
                ViewBag.Cities            = new SelectList(_city.Cities, "CityId", "CityName");
                ViewBag.AddressTypes      = new SelectList(_addressType.addressTypes, "AddressTypeId", "AddressTypeName");
                ViewBag.TeacherHiringType = new SelectList(_teacherHiringType.GetAll, "TeacherHiringTypeId", "TeacherHiringTypeName");
                ViewBag.EducationType     = new SelectList(_educationType.GetAll, "EducationTypeId", "EducationTypeName");
                ViewBag.TeacherEducation  = new SelectList(_teacherEducation.GetAll, "TeacherEducationId", "TeacherEducationTitle");
                ViewBag.Nationality       = new SelectList(_nationality.GetAll, "NationalityId", "NationalityName");
                ViewBag.MatirialStatus    = new SelectList(_matirialStatus.GetAll, "MaritalStatusId", "MaritalStatusName");


                return(View("Crear", model));
            }


            return(RedirectToAction("Index", new { UniversityId = model.UniversityId }));
        }