Пример #1
0
        //[HttpPost]
        public IActionResult AgregarConvocatoria(ScholarshipProgramUniversityModel model)
        {
            if (ModelState.IsValid)
            {
                var data = CopyPropierties.Convert <ScholarshipProgramUniversityModel, ScholarshipProgramUniversity>(model);

                try
                {
                    _scholarshipProgramUniversity.Save(data);
                }
                catch (Exception e)
                {
                    return(RedirectToAction("Editar", new { id = model.ScholarshipProgramId }));
                }
            }
            else
            {
                var errors = ModelState.Select(x => x.Value.Errors).FirstOrDefault(x => x.Count > 0).First();

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


                return(RedirectToAction("Editar", new { id = model.ScholarshipProgramId }));
            }



            return(RedirectToAction("Editar", new { id = model.ScholarshipProgramId }));
        }
        public IActionResult GuardarEmpleado(EmpleadoViewModel model)
        {
            var empleadoData = _empleado.GetAll;

            if (ModelState.IsValid)
            {
                var data = CopyPropierties.Convert <EmpleadoViewModel, Empleado>(model);


                try
                {
                    _empleado.Save(data);
                }
                catch (Exception e)
                {
                    ViewBag.Posiciones = new SelectList(_posicion.GetAll, "PosicionId", "PosicionName");
                    return(View("Crear", model));
                }
            }
            else
            {
                var errors = ModelState.Select(x => x.Value.Errors).FirstOrDefault(x => x.Count() > 0).First();

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

                ViewBag.Posiciones = new SelectList(_posicion.GetAll, "PosicionId", "PosicionName");
                return(View("Crear", model));
            }


            EnviarMensaje.Enviar(TempData, "green", "La informacion fue guardada");
            return(View("Index", empleadoData));
        }
Пример #3
0
        public IActionResult GuardarTeacherEducation(TeacherEducationModel model)
        {
            var data = CopyPropierties.Convert <TeacherEducationModel, TeacherEducation>(model);

            if (ModelState.IsValid)
            {
                try
                {
                    _teacherEducation.Save(data);
                }
                catch (Exception e) {
                    return(RedirectToAction("TeacherEducation", 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);

                return(RedirectToAction("TeacherEducation", new { id = model.TeacherId }));
            }

            return(RedirectToAction("TeacherEducation", new { id = model.TeacherId }));
        }
Пример #4
0
        public IActionResult AgregarComunicacion(ContactCommunicationModel model)
        {
            var data = CopyPropierties.Convert <ContactCommunicationModel, ContactCommunication>(model);

            if (string.IsNullOrWhiteSpace(model.Communication.CommunicationPhoneNumber1) && string.IsNullOrWhiteSpace(model.Communication.CommunicationPhoneNumber2))
            {
                EnviarMensaje.Enviar(TempData, "red", "Al menos un número de contacto es requerido");
                return(RedirectToAction("AgregarComunicacion", new { id = model.TeacherId }));
            }

            if (string.IsNullOrWhiteSpace(model.Communication.CommunicationEmail))
            {
                EnviarMensaje.Enviar(TempData, "red", "El email es requerido ");
                return(RedirectToAction("AgregarComunicacion", new { id = model.TeacherId }));
            }

            try
            {
                _contactCommunication.Save(data);
            }
            catch (Exception e)
            {
                return(RedirectToAction("AgregarComunicacion", new { id = model.TeacherId }));
            }

            return(RedirectToAction("AgregarComunicacion", new { id = model.TeacherId }));
        }
Пример #5
0
        public IActionResult GuardarPosicion(PosicionViewModel model)
        {
            var posicionData = _posicion.GetAll;

            if (ModelState.IsValid)
            {
                var data = CopyPropierties.Convert <PosicionViewModel, Posicion>(model);
                try
                {
                    _posicion.Save(data);
                }
                catch (Exception e)
                {
                    EnviarMensaje.Enviar(TempData, "red", "Verifique el formulario");
                    return(View("Crear", model));
                }
            }
            else
            {
                EnviarMensaje.Enviar(TempData, "red", "Verifique el formulario");

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


            EnviarMensaje.Enviar(TempData, "green", "La informacion fue guardada");
            return(View("Index", posicionData));
        }
Пример #6
0
        public IActionResult EditarAcuerdos(EditarAcuerdoViewModel model, int acuerdoId, int scholarshipProgramUniversityId)
        {
            if (ModelState.IsValid)
            {
                var data = CopyPropierties.Convert <EditarAcuerdoViewModel, ScholarshipProgramUniversityAgreement>(model);

                try
                {
                    _scholarshipProgramUniversityAgreement.Save(data);
                }
                catch (Exception e)
                {
                    return(RedirectToAction("EditarAcuerdos", new { acuerdoId = model.ScholarshipProgramUniversityAgreementId, scholarshipProgramUniversityId = model.ScholarshipProgramUniversityId }));
                }
            }
            else
            {
                var errors = ModelState.Select(x => x.Value.Errors).FirstOrDefault(x => x.Count() > 0).First();

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

                return(RedirectToAction("EditarAcuerdos", new { acuerdoId = model.ScholarshipProgramUniversityAgreementId, scholarshipProgramUniversityId = model.ScholarshipProgramUniversityId }));
            }



            return(RedirectToAction("Editar", new { id = model.ScholarshipProgramUniversityId }));
        }
        public IActionResult GuardarUniverity(UniversityModel model)
        {
            if (string.IsNullOrWhiteSpace(model.Address.Address1) || string.IsNullOrWhiteSpace(model.Communication.CommunicationEmail))
            {
                EnviarMensaje.Enviar(TempData, "red", "Dirección 1  y el Email son requeridos");

                ViewBag.Status      = new SelectList(_status.Status, "StatusId", "StatusName");
                ViewBag.AddressType = new SelectList(_addressType.addressTypes, "AddressTypeId", "AddressTypeName");
                ViewBag.Country     = new SelectList(_country.GetAll, "CountryId", "CountryName");
                ViewBag.Province    = new SelectList(_province.Provinces, "ProvinceId", "ProvinceName");
                ViewBag.City        = new SelectList(_city.Cities, "CityId", "CityName");

                return(View("Crear"));
            }


            if (ModelState.IsValid)
            {
                var university = CopyPropierties.Convert <UniversityModel, University>(model);

                try
                {
                    _university.Save(university);
                }
                catch (Exception e)
                {
                    return(View("Index", _university.Universities));
                }
            }
            else
            {
                var errors = ModelState.Select(x => x.Value.Errors).FirstOrDefault(x => x.Count > 0).First();

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


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

                ViewBag.Status      = new SelectList(_status.Status, "StatusId", "StatusName");
                ViewBag.AddressType = new SelectList(_addressType.addressTypes, "AddressTypeId", "AddressTypeName");
                ViewBag.Country     = new SelectList(_country.GetAll, "CountryId", "CountryName");
                ViewBag.Province    = new SelectList(_province.Provinces, "ProvinceId", "ProvinceName");
                ViewBag.City        = new SelectList(_city.Cities, "CityId", "CityName");

                return(View("Crear"));
            }



            return(View("Index", _university.Universities));
        }
Пример #8
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 }));
        }
Пример #9
0
        public IActionResult GuardarPrograma(ScholarshipProgramModel model, string prueba)
        {
            if (ModelState.IsValid)
            {
                var scholarshipProgramModel = new ScholarshipProgram
                {
                    ScholarshipProgramId   = model.ScholarshipProgramId,
                    ScholarshipProgramName = model.ScholarshipProgramName,
                    ScholarshipLevelId     = model.ScholarshipLevelId,
                    CreationDate           = model.CreationDate,
                    UpgradeDate            = model.UpgradeDate,
                    StatusId         = model.StatusId,
                    ScholarshipLevel = model.ScholarshipLevel,
                    Status           = model.Status,
                };



                try
                {
                    _scholarshipProgram.GuardarScholarshipProgram(scholarshipProgramModel);
                }

                catch (Exception e)
                {
                    ViewBag.Nivel      = new SelectList(_scholarshipLevel.ScholarshipsLevel, "ScholarshipLevelId", "ScholarshipLevelName");
                    ViewBag.Status     = new SelectList(_status.Status, "StatusId", "StatusName");
                    ViewBag.University = new SelectList(_university.Universities, "UniversityId", "UniversityName");
                    return(View("Crear", model));
                }
            }
            else
            {
                var errors = ModelState.Select(x => x.Value.Errors).FirstOrDefault(x => x.Count > 0).First();

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

                ViewBag.Nivel      = new SelectList(_scholarshipLevel.ScholarshipsLevel, "ScholarshipLevelId", "ScholarshipLevelName");
                ViewBag.Status     = new SelectList(_status.Status, "StatusId", "StatusName");
                ViewBag.University = new SelectList(_university.Universities, "UniversityId", "UniversityName");
                return(View("Crear", model));
            }



            return(View("Index", _scholarshipProgram.GetAll.ToList()));
        }
        public IActionResult GuardarConvocatoriaDeBeca(ScholarshipProgramUniversityModel model)
        {
            var data = CopyPropierties.Convert <ScholarshipProgramUniversityModel, ScholarshipProgramUniversity>(model);

            if (ModelState.IsValid)
            {
                try
                {
                    _scholarshipProgramUniversity.Save(data);
                }
                catch (Exception e)
                {
                    return(RedirectToAction("Editar", new { id = model.ScholarshipProgramUniversityId }));
                }
            }
            else
            {
                var errors = ModelState.Select(x => x.Value.Errors).FirstOrDefault(x => x.Count > 0).First();

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

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

                var technicals = _agent.GetTechnicals.Select(x => new GetAgents {
                    AgentTypeId = x.AgentTypeId, FullName = x.Contact.ContactName.ToString() + " " + x.Contact.ContactLastname
                });
                var coordinators = _agent.GetCoordinators.Select(x => new GetAgents {
                    AgentTypeId = x.AgentTypeId, FullName = x.Contact.ContactName.ToString() + " " + x.Contact.ContactLastname
                });

                ViewBag.Coordinator        = new SelectList(coordinators, "AgentTypeId", "FullName");
                ViewBag.Technical          = new SelectList(technicals, "AgentTypeId", "FullName");
                ViewBag.University         = new SelectList(_university.Universities, "UniversityId", "UniversityName");
                ViewBag.Nivel              = new SelectList(_scholarshipLevel.ScholarshipsLevel, "ScholarshipLevelId", "ScholarshipLevelName");
                ViewBag.scholarshipProgram = new SelectList(_scholarshipProgram.GetAll, "ScholarshipProgramId", "ScholarshipProgramName");
                ViewBag.Status             = new SelectList(_status.Status, "StatusId", "StatusName");

                return(View("Crear"));
            }



            return(RedirectToAction("Index"));
        }
Пример #11
0
        public IActionResult AgregarAcuerdo(AcuerdoProgramasdeBecaModel model)
        {
            if (model.AgreementId == 0 || string.IsNullOrWhiteSpace(model.ScholarshipProgramUniversityAgreement1))
            {
                EnviarMensaje.Enviar(TempData, "red", "Ambos campos son requeridos");

                return(RedirectToAction("Editar", new { id = model.ScholarshipProgramUniversityId }));
            }


            if (ModelState.IsValid)
            {
                var scholarshipProgramUniversityAgreement = new ScholarshipProgramUniversityAgreement
                {
                    ScholarshipProgramUniversityAgreementId = model.Agreement.ScholarshipProgramUniversityAgreementId,
                    ScholarshipProgramUniversityId          = model.ScholarshipProgramUniversityId,
                    ScholarshipProgramUniversityAgreement1  = model.ScholarshipProgramUniversityAgreement1,
                    AgreementTypeId = model.AgreementId,
                    StatusId        = 1
                };

                if (model.Agreement.AgreementTypeId != 0)
                {
                }
                try
                {
                    _scholarshipProgramUniversityAgreement.Save(scholarshipProgramUniversityAgreement);
                }
                catch (Exception e)
                {
                    return(RedirectToAction("Editar", new { id = model.ScholarshipProgramUniversityId }));
                }
            }
            else
            {
                var errors = ModelState.Select(x => x.Value.Errors).FirstOrDefault(x => x.Count > 0).First();



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

                return(RedirectToAction("Editar", new { id = model.ScholarshipProgramUniversityId }));
            }


            return(RedirectToAction("Editar", new { id = model.ScholarshipProgramUniversityId }));
        }
Пример #12
0
        //[Authorize(Policy = Constante.UsuarioCanUpdate)]
        public async Task <IActionResult> CambiarEstado(EditarUsuarioModel model)
        {
            var usuarioCreado = _usuario.GetUsuarioById(model.Id);

            if (usuarioCreado.Role != null)
            {
                if (TryValidateModel(model))
                {
                    PropertiesParser <EditarUsuarioModel, Usuario>
                    .CopyPropertiesTo <EditarUsuarioModel, Usuario>(model, usuarioCreado);

                    await _userManager.UpdateAsync(usuarioCreado);

                    var roles = await _userManager.GetRolesAsync(usuarioCreado);

                    if (!string.IsNullOrEmpty(model.Role))
                    {
                        if (!roles.Contains(model.Role))
                        {
                            await _userManager.AddToRoleAsync(usuarioCreado, model.Role);
                        }
                    }

                    EnviarMensaje.Enviar(TempData, "green", 3);


                    return(View("Index", _usuario.Usuarios));
                }
            }
            else
            {
                EnviarMensaje.Enviar(TempData, "red", "El usuario debe tener un rol asignado");


                return(View("Index", _usuario.Usuarios));
            }



            return(View("Index", _usuario.Usuarios));
        }
Пример #13
0
        public IActionResult AgregarDireccion(ContactAddressModel model)
        {
            var data = CopyPropierties.Convert <ContactAddressModel, ContactAddress>(model);

            if (ModelState.IsValid)
            {
                try
                {
                    _contactAddress.Save(data);
                }
                catch (Exception e)
                {
                    return(RedirectToAction("AgregarDireccion", 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);


                var contactId   = _teacher.GetContactId((int)model.TeacherId);
                var teacherById = _teacher.GetById((int)model.TeacherId);

                model.ContactId          = contactId;
                model.TeacherId          = teacherById.TeacherId;
                model.TeacherFullName    = teacherById.Contact.ContactName + " " + teacherById.Contact.ContactLastname;
                model.ContactAddressList = _contactAddress.GetByContactId(contactId).ToList();

                ViewBag.Countries    = new SelectList(_country.GetAll, "CountryId", "CountryName");
                ViewBag.Cities       = new SelectList(_city.Cities, "CityId", "CityName");
                ViewBag.Province     = new SelectList(_province.Provinces, "ProvinceId", "ProvinceName");
                ViewBag.AddressTypes = new SelectList(_addressType.addressTypes, "AddressTypeId", "AddressTypeName");

                return(View(model));
            }


            return(RedirectToAction("AgregarDireccion", new { id = model.TeacherId }));
        }
Пример #14
0
        //[Authorize(Policy = Constante.UsuarioCanUpdate)]
        public async Task <ActionResult> ResetPassword(ResetPasswordViewModel model)
        {
            var usuario = _usuario.GetUsuarioById(model.Id);
            var roles   = _role.Roles.ToList();

            var perfilmodel = new PerfilUsuario
            {
                EditarUsuarioModel     = CopyPropierties.Convert <Usuario, EditarUsuarioModel>(usuario),
                ResetPasswordViewModel = model
            };


            //if (model == null) return View(model);
            MensajesViewModel mensaj = new MensajesViewModel();
            var user = await _userManager.FindByNameAsync(model.UserName);



            if (model.Url == "PerfilUsuarioAdmin")
            {
                if (model.Password == null || model.ConfirmPassword == null)
                {
                    EnviarMensaje.Enviar(TempData, "red", 12);
                    ViewBag.Role = new SelectList(roles, "Name", "Name");
                    return(View("PerfilUsuarioAdmin", perfilmodel));
                }

                else if (model.Password != model.ConfirmPassword)
                {
                    EnviarMensaje.Enviar(TempData, "red", 13);
                    ViewBag.Role = new SelectList(roles, "Name", "Name");
                    return(View("PerfilUsuarioAdmin", perfilmodel));
                }
                else
                {
                    var result = await _userManager.ResetPasswordAsync(user, model.Code, model.Password);

                    if (result.Succeeded)
                    {
                        //ViewBag.Role = new SelectList(roles, "Name", "Name");
                        EnviarMensaje.Enviar(TempData, "green", 12);
                        return(RedirectToAction("PerfilUsuarioAdmin", "Usuario", new { id = model.Id }));
                    }
                }
            }

            else
            {
                if (model.Password == null || model.ConfirmPassword == null)
                {
                    EnviarMensaje.Enviar(TempData, "red", 12);
                    //ViewBag.Role = new SelectList(roles, "Name", "Name");
                    return(View("Index", _usuario.Usuarios));
                }
                else if (model.Password.Length < 6)
                {
                    EnviarMensaje.Enviar(TempData, "red", "La contraseña debe ser de por lo menos 6 caracteres de longitud");
                    return(View("Index", _usuario.Usuarios));
                }

                else if (model.Password != model.ConfirmPassword)
                {
                    EnviarMensaje.Enviar(TempData, "red", 13);
                    return(View("Index", _usuario.Usuarios));
                }
                //else if (model.Password.Length < 6 && model.con)
                else
                {
                    var result = await _userManager.ResetPasswordAsync(user, model.Code, model.Password);

                    if (result.Succeeded)
                    {
                        EnviarMensaje.Enviar(TempData, "green", 12);


                        return(View("Index", _usuario.Usuarios));
                    }
                }
            }



            if (user == null)
            {
                // Don't reveal that the user does not exist
                return(View("login"));
            }

            //model.ResetPasswordViewModel.Code = UserManager.GeneratePasswordResetToken(user.Id);
            //model.Code = await _userManager.GeneratePasswordResetTokenAsync(user);

            ViewBag.Role = new SelectList(roles, "Name", "Name");

            return(View("PerfilUsuarioAdmin", perfilmodel));
        }
Пример #15
0
        public async Task <IActionResult> File(TeacherFileModel model, IFormFile file)
        {
            var rutaPdf = _config.GetSection("rutas").GetSection("TeacherFiles").Value;

            //var file = model.FormFile;
            if (model.TeacherFileTypeId == null)
            {
                EnviarMensaje.Enviar(TempData, "red", "El tipo de archivo es requerido");


                return(RedirectToAction("AgregarDocumento", new { id = model.TeacherId }));
            }


            if (file != null)
            {
                //upload files to wwwroot
                //var fileName = Path.GetFileName(file.FileName);

                //judge if it is pdf file
                string ext      = Path.GetExtension(file.FileName);
                var    fileName = model.TeacherId + "-" + Guid.NewGuid() + ext;
                if (ext.ToLower() != ".pdf")
                {
                    return(RedirectToAction("AgregarDocumento", new { id = model.TeacherId }));
                }
                var fileFullPath = Path.Combine(rutaPdf, fileName);
                //var filePath = "\\app-assets\\documentos\\teacher" + fileName;

                using (var fileSteam = new FileStream(fileFullPath, FileMode.Create))
                {
                    await file.CopyToAsync(fileSteam);
                }
                //your logic to save filePath to database, for example


                model.File.FileName     = file.FileName;
                model.File.FilePath     = fileName;
                model.File.FileFullPath = fileFullPath;
                model.File.FileTypeId   = model.TeacherFileTypeId;


                var data = CopyPropierties.Convert <TeacherFileModel, TeacherFile>(model);

                try
                {
                    _teacherFile.Save(data);
                }
                catch (Exception e)
                {
                    return(RedirectToAction("AgregarDocumento", new { id = model.TeacherId }));
                }
            }
            else
            {
                EnviarMensaje.Enviar(TempData, "red", "El archivo es requerido");

                return(RedirectToAction("AgregarDocumento", new { id = model.TeacherId }));
            }



            return(RedirectToAction("AgregarDocumento", new { id = model.TeacherId }));
        }
Пример #16
0
        public IActionResult Guardar(AgentModel model)
        {
            var data = CopyPropierties.Convert <AgentModel, Agent>(model);
            var contactComunicationModel = new  ContactCommunication();

            data.Contact.ContactCommunication.ContactId = model.ContactId;


            if (ModelState.IsValid)
            {
                if (_contact.CheckIfContactDocumentNumberExits(data.Contact))
                {
                    EnviarMensaje.Enviar(TempData, "red", "Ya existe un registro con este número documento");

                    ViewBag.ContactType  = new SelectList(_contactType.GetAll, "ContactTypeId", "ContactTypeName");
                    ViewBag.AgentType    = new SelectList(_agentType.GetAll, "AgentTypeId", "AgentTypeName");
                    ViewBag.DocumentType = new SelectList(_documentType.GetAll, "DocumentTypeId", "DocumentTypeName");
                    ViewBag.AddressType  = new SelectList(_addressType.addressTypes, "AddressTypeId", "AddressTypeName");
                    ViewBag.Countries    = new SelectList(_country.GetAll, "CountryId", "CountryName");
                    ViewBag.Provinces    = new SelectList(_province.Provinces, "ProvinceId", "ProvinceName");
                    ViewBag.Cities       = new SelectList(_city.Cities, "CityId", "CityName");
                    ViewBag.Status       = new SelectList(_status.Status, "StatusId", "StatusName");
                    return(View("Crear", model));
                }

                try
                {
                    _agent.Save(data);
                }
                catch (Exception e)
                {
                    ViewBag.ContactType  = new SelectList(_contactType.GetAll, "ContactTypeId", "ContactTypeName");
                    ViewBag.AgentType    = new SelectList(_agentType.GetAll, "AgentTypeId", "AgentTypeName");
                    ViewBag.DocumentType = new SelectList(_documentType.GetAll, "DocumentTypeId", "DocumentTypeName");
                    ViewBag.AddressType  = new SelectList(_addressType.addressTypes, "AddressTypeId", "AddressTypeName");
                    ViewBag.Countries    = new SelectList(_country.GetAll, "CountryId", "CountryName");
                    ViewBag.Provinces    = new SelectList(_province.Provinces, "ProvinceId", "ProvinceName");
                    ViewBag.Cities       = new SelectList(_city.Cities, "CityId", "CityName");
                    ViewBag.Status       = new SelectList(_status.Status, "StatusId", "StatusName");
                    return(View("Crear", model));
                }
            }
            else
            {
                var erros = ModelState.Select(x => x.Value.Errors).FirstOrDefault(x => x.Count() > 0).First();

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

                ViewBag.ContactType  = new SelectList(_contactType.GetAll, "ContactTypeId", "ContactTypeName");
                ViewBag.AgentType    = new SelectList(_agentType.GetAll, "AgentTypeId", "AgentTypeName");
                ViewBag.DocumentType = new SelectList(_documentType.GetAll, "DocumentTypeId", "DocumentTypeName");
                ViewBag.AddressType  = new SelectList(_addressType.addressTypes, "AddressTypeId", "AddressTypeName");
                ViewBag.Countries    = new SelectList(_country.GetAll, "CountryId", "CountryName");
                ViewBag.Provinces    = new SelectList(_province.Provinces, "ProvinceId", "ProvinceName");
                ViewBag.Cities       = new SelectList(_city.Cities, "CityId", "CityName");
                ViewBag.Status       = new SelectList(_status.Status, "StatusId", "StatusName");
                return(View("Crear", model));
            }



            return(View("Index", _agent.Agents.DistinctBy(x => x.AgentId).ToList()));
        }
Пример #17
0
        public IActionResult Guardar(SubjectMatterModel model)
        {
            var universityId          = _scholarshipProgramUniversity.GetUniversityIdByScholarshipProgramUniversityId(model.ScholarshipProgramUniversityId);
            MensajesViewModel mensaje = new MensajesViewModel();
            var data = CopyPropierties.Convert <SubjectMatterModel, SubjectMatter>(model);

            if (CheckIfSubjectMatterCodeExits(data))
            {
                EnviarMensaje.Enviar(TempData, "red", "Este programa ya contiene un registro de una materia con este código");

                //if (model.SubjectMatterId != 0)
                //{
                //    ViewBag.Teachers = new SelectList(TeachersByUniverityIdList(universityId), "TeacherId", "TeacherFullName");
                //    return RedirectToAction("Editar", new { id = model.SubjectMatterId, scholarshipProgramUniversityId = model.ScholarshipProgramUniversityId });
                //}


                ViewBag.Status   = new SelectList(_status.Status, "StatusId", "StatusName");
                ViewBag.Teachers = new SelectList(TeachersByUniverityIdList(universityId), "TeacherId", "TeacherFullName");
                return(View("Crear", model));
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _subjectMatter.Save(data);
                }
                catch (Exception e)
                {
                    if (model.SubjectMatterId != 0)
                    {
                        ViewBag.Teachers = new SelectList(TeachersByUniverityIdList(universityId), "TeacherId", "TeacherFullName");
                        return(RedirectToAction("Editar", new { id = model.SubjectMatterId, scholarshipProgramUniversityId = model.ScholarshipProgramUniversityId }));
                    }
                    else
                    {
                        ViewBag.Status   = new SelectList(_status.Status, "StatusId", "StatusName");
                        ViewBag.Teachers = new SelectList(TeachersByUniverityIdList(universityId), "TeacherId", "TeacherFullName");
                        return(View("Crear"));
                    }
                }
            }
            else
            {
                var errors = ModelState.Select(x => x.Value.Errors).FirstOrDefault(x => x.Count > 0).First();



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

                if (model.SubjectMatterId != 0)
                {
                    ViewBag.Teachers = new SelectList(TeachersByUniverityIdList(universityId), "TeacherId", "TeacherFullName");
                    return(RedirectToAction("Editar", new { id = model.SubjectMatterId, scholarshipProgramUniversityId = model.ScholarshipProgramUniversityId }));
                }
                ViewBag.Status   = new SelectList(_status.Status, "StatusId", "StatusName");
                ViewBag.Teachers = new SelectList(TeachersByUniverityIdList(universityId), "TeacherId", "TeacherFullName");
                return(View("Crear"));
            }


            return(RedirectToAction("Index", new { scholarshipProgramUniversityId = model.ScholarshipProgramUniversityId }));
        }
Пример #18
0
        public async Task <IActionResult> Editar(PerfilUsuario model, IFormFile imagen)
        {
            var    size    = 3145728;
            var    rutaImg = _config.GetSection("rutas").GetSection("usuario").Value;
            string ext     = imagen != null?Path.GetExtension(imagen.FileName) : "";

            // Validar imagen
            var resp = ValidacionDocumento.Validar(imagen, size, ext, string.IsNullOrEmpty(model.EditarUsuarioModel.Imagen));

            if (resp > 1)
            {
                //ViewBag.tipo = new SelectList(_tipo.Tipos, "TipoProductoId", "Nombre", model.TipoProductoId);

                EnviarMensaje.Enviar(TempData, "red", resp);

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


            if (TryValidateModel(model.EditarUsuarioModel))
            {
                var usuarioCreado = _usuario.GetUsuarioById(model.EditarUsuarioModel.Id);

                PropertiesParser <EditarUsuarioModel, Usuario>
                .CopyPropertiesTo <EditarUsuarioModel, Usuario>(model.EditarUsuarioModel, usuarioCreado);

                var name = usuarioCreado.Id + "-" + Guid.NewGuid() + ext;

                if (imagen != null)
                {
                    usuarioCreado.Imagen = name;
                }

                var result = await _userManager.UpdateAsync(usuarioCreado);

                var roles = await _userManager.GetRolesAsync(usuarioCreado);

                if (!string.IsNullOrEmpty(model.EditarUsuarioModel.Role))
                {
                    if (!roles.Contains(model.EditarUsuarioModel.Role))
                    {
                        await _userManager.AddToRoleAsync(usuarioCreado, model.EditarUsuarioModel.Role);
                    }
                }

                if (usuarioCreado.Imagen != null)
                {
                    if (result.Succeeded)
                    {
                        await ValidacionDocumento.GuardarDocumentoAsync(imagen, rutaImg, name);
                    }

                    EnviarMensaje.Enviar(TempData, "green", 3);



                    return(RedirectToAction("Home", "Home", new { area = "" }));
                }
                else
                {
                    if (result.Succeeded)
                    {
                        await ValidacionDocumento.GuardarDocumentoAsync(imagen, rutaImg, name);
                    }

                    EnviarMensaje.Enviar(TempData, "green", 3);



                    return(RedirectToAction("Home", "Home", new { area = "" }));
                }
            }


            return(RedirectToAction("PerfilUsuario", new { id = model.EditarUsuarioModel.Id }));
        }
Пример #19
0
        //[Authorize(Policy = Constante.UsuariorCanCreate)]
        public async Task <IActionResult> Registro(RegisterViewModel model)
        {
            if (ModelState.IsValid)
            {
                MensajesViewModel mensaje = new MensajesViewModel();

                var user  = CopyPropierties.Convert <RegisterViewModel, Usuario>(model);
                var email = _usuario.Usuarios.FirstOrDefault(x => x.Email.Equals(model.Email));
                user.EmailConfirmed = true;

                //ViewData["Prueba"] =  _localizer["Este email ya existe, intenten con otro"];



                try
                {
                    if (model.Password.Length < 6)
                    {
                        mensaje.Titulo = "La Contraseña debe contener al menos 6 digitos";
                    }

                    else if (email != null)
                    {
                        mensaje.Titulo = "Este email ya existe, intenten con otro";
                        //ViewData["Prueba"] = _localizer["Clientes"];
                    }
                    else
                    {
                        var result = await _userManager.CreateAsync(user, model.Password);


                        if (result.Succeeded)
                        {
                            if (!string.IsNullOrEmpty(user.Role))
                            {
                                result = await _userManager.AddToRoleAsync(user, user.Role);
                            }

                            //mensaje.Titulo = "Usuario Creado";

                            //mensaje.Texto = "El usuario se creó satisfactoriamente";

                            //mensaje.Tipo = "success";

                            EnviarMensaje.Enviar(TempData, "green", "El usuario se creó satisfactoriamente");


                            return(RedirectToAction("Index", "Usuario"));
                        }

                        mensaje.Titulo = "Hubo un problema";

                        if (result.Errors.First().Code == "DuplicateUserName")
                        {
                            mensaje.Texto = "El nombre de usuario ya exite, intenten con otro";
                        }
                    }

                    mensaje.Tipo    = "error";
                    ViewBag.mensaje = mensaje;

                    return(View("Register", model));
                }
                catch (System.Exception e)
                {
                    var error = e;
                    return(View(model));
                }
            }

            return(View("Register", model));
        }
Пример #20
0
        public async Task <ActionResult> ResetPassword(ResetPasswordViewModel model)
        {
            var usuario     = _usuario.GetUsuarioById(model.Id);
            var perfilmodel = new PerfilUsuario
            {
                EditarUsuarioModel     = CopyPropierties.Convert <Usuario, EditarUsuarioModel>(usuario),
                ResetPasswordViewModel = model
            };


            //if (model == null) return View(model);
            MensajesViewModel mensaj = new MensajesViewModel();
            var user = await _userManager.FindByNameAsync(model.UserName);


            if (model.Url == "Index")
            {
                var result = await _userManager.ResetPasswordAsync(user, model.Code, model.Password);

                if (result.Succeeded)
                {
                    EnviarMensaje.Enviar(TempData, "green", 12);

                    //return RedirectToAction("PerfilUsuario", new RouteValueDictionary(new { Controller = "Usuario", Action = "PerfilUsuario", Id = "eeed77ad - 8815 - 4d7a - b5d5 - fa6a1393b6e2" }));
                    return(View("Index", _usuario.Usuarios));
                }
            }

            if (model.Password == null || model.ConfirmPassword == null)
            {
                EnviarMensaje.Enviar(TempData, "red", 12);
                return(View("PerfilUsuario", perfilmodel));
            }

            else if (model.Password != model.ConfirmPassword)
            {
                EnviarMensaje.Enviar(TempData, "red", 13);
                return(View("PerfilUsuario", perfilmodel));
            }
            else
            {
                var result = await _userManager.ResetPasswordAsync(user, model.Code, model.Password);

                if (result.Succeeded)
                {
                    EnviarMensaje.Enviar(TempData, "green", 12);

                    return(RedirectToAction("PerfilUsuario", "Account", new { id = model.Id }));

                    //RedirectToAction("PerfilUsuario", "Usuario", model.Id);
                }
            }


            if (user == null)
            {
                // Don't reveal that the user does not exist
                return(View("login"));
            }



            return(View("PerfilUsuario", perfilmodel));
        }
Пример #21
0
        //[Authorize(Policy = Constante.UsuarioCanUpdate)]
        public async Task <IActionResult> Editar(PerfilUsuario model)
        {
            //var editar = model.EditarUsuarioModel;
            //MensajesViewModel mensaje = new MensajesViewModel();

            if (TryValidateModel(model.EditarUsuarioModel))
            {
                var usuarioCreado = _usuario.GetUsuarioById(model.EditarUsuarioModel.Id);
                //var roleslist = _roleManger.Roles.ToList();
                var     userId = this.User.FindFirstValue(ClaimTypes.NameIdentifier);
                Usuario user   = _userManager.FindByIdAsync(userId).Result;


                //var claims = User.Claims.ToList();
                //var claimsPrueba = User.Claims.ToList().FirstOrDefault(x=> x.Value == usuarioCreado.Role);

                //foreach (var role in roleslist)
                //{

                //    foreach(var claim in claims)
                //    {
                //    await _roleManger.RemoveClaimAsync(role, claim);

                //    }

                //}

                var claims            = User.Claims.ToList();;
                var lastAccessedClaim = claims.ToList();

                foreach (var claim in claims)
                {
                    var resDelete = (lastAccessedClaim == null) ? null : await _userManager.RemoveClaimAsync(user, claim);

                    var prueba = "";
                }


                var claimsPrueba = User.Claims.ToList();

                PropertiesParser <EditarUsuarioModel, Usuario>
                .CopyPropertiesTo <EditarUsuarioModel, Usuario>(model.EditarUsuarioModel, usuarioCreado);

                await _userManager.UpdateAsync(usuarioCreado);

                var roles = await _userManager.GetRolesAsync(usuarioCreado);

                if (!string.IsNullOrEmpty(model.EditarUsuarioModel.Role))
                {
                    if (!roles.Contains(model.EditarUsuarioModel.Role))
                    {
                        await _userManager.AddToRoleAsync(usuarioCreado, model.EditarUsuarioModel.Role);
                    }
                }

                //mensaje.Titulo = "Usuario Actualizado";
                //mensaje.Texto = usuarioCreado.Nombre + " " + usuarioCreado.Apellido + "ha sido actualizado correctamente";
                //mensaje.Tipo = "green";

                EnviarMensaje.Enviar(TempData, "green", 3);



                return(View("Index", _usuario.Usuarios));
            }

            //mensaje.Titulo = "Hubo un error";
            //mensaje.Texto = "verifique los campos que desea cambiar";
            //mensaje.Tipo = "red";

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