Esempio n. 1
0
        public async Task <IActionResult> listarPickeadores([FromRoute] string NombreRol)
        {
            if (!ModelState.IsValid)
            {
                return(Json(new { success = false, message = ErrorModelValidation.ShowError(new SerializableError(ModelState).Values) }));
            }

            try
            {
                var Usuarios  = _userManager.Users.ToList();
                var lstResult = new List <Usuario>();

                foreach (var Usuario in Usuarios)
                {
                    var Roles = _userManager.GetRolesAsync(Usuario).Result.ToList();
                    foreach (var Rol in Roles)
                    {
                        if (Rol == NombreRol)
                        {
                            lstResult.Add(new Usuario {
                                Nombre = Usuario.Nombre, Id = Usuario.Id, Email = Usuario.Email, Activo = Usuario.Activo
                            });
                        }
                    }
                }

                return(Json(new { success = true, message = lstResult }));
            }
            catch (Exception exc)
            {
                string ErrorMsg = exc.GetBaseException().InnerException != null?exc.GetBaseException().InnerException.Message : exc.GetBaseException().Message;

                return(Json(new { success = false, message = "Error! " + ErrorMsg }));
            }
        }
Esempio n. 2
0
        public async Task <IActionResult> CancelMedicalAppointment([FromRoute] int id)
        {
            if (!ModelState.IsValid)
            {
                return(Json(new { success = false, message = ErrorModelValidation.ShowError(new SerializableError(ModelState).Values) }));
            }

            try
            {
                var entity = LMedicalAppointment.GetMedicalAppointmentById(id, _repository);

                if (entity == null)
                {
                    Json(new { success = false, message = "No se pudo encontrar el registro indicado." });
                }

                LMedicalAppointment.CancelMedicalAppointment(entity, _repository, _IunitOfWork);
                return(Json(new { success = true, message = "Registro cancelado correctamente." }));
            }
            catch (Exception exc)
            {
                string ErrorMsg = exc.GetBaseException().InnerException != null?exc.GetBaseException().InnerException.Message : exc.GetBaseException().Message;

                return(Json(new { success = false, message = "Error!. " + ErrorMsg }));
            }
        }
Esempio n. 3
0
        public async Task <IActionResult> GetUser([FromRoute] string id)
        {
            if (!ModelState.IsValid)
            {
                return(Json(new { success = false, message = ErrorModelValidation.ShowError(new SerializableError(ModelState).Values) }));
            }

            try
            {
                var Usuario    = _userManager.FindByIdAsync(id).Result;
                var totalRoles = _rolManager.Roles.ToList();
                var Roles      = _userManager.GetRolesAsync(Usuario).Result.ToList();
                var user       = new Usuario {
                    Id = Usuario.Id, Email = Usuario.Email, Nombre = Usuario.Nombre, Activo = Usuario.Activo
                };
                totalRoles.ForEach(x => user.Roles.Add(new RolViewModel {
                    Nombre = x.Name, Seleccionado = Roles.Any(y => y == x.Name) ? true : false
                }));

                return(Json(new { success = true, message = user }));
            }
            catch (Exception exc)
            {
                string ErrorMsg = exc.GetBaseException().InnerException != null?exc.GetBaseException().InnerException.Message : exc.GetBaseException().Message;

                return(Json(new { success = false, message = "Error!. " + ErrorMsg }));
            }
        }
Esempio n. 4
0
        public async Task <IActionResult> EditUser([FromRoute] string id, [FromBody] Usuario model)
        {
            if (!ModelState.IsValid)
            {
                return(Json(new { success = false, message = ErrorModelValidation.ShowError(new SerializableError(ModelState).Values) }));
            }

            try
            {
                var result = _userManager.FindByIdAsync(id).Result;

                if (result != null)
                {
                    var Usuario = _context.Users.Where(x => x.Id == id).FirstOrDefault();
                    Usuario.Nombre = model.Nombre;
                    Usuario.Activo = model.Activo;
                    _context.SaveChanges();

                    await AsignarRolAsync(_context, Usuario, model.Roles);

                    return(Json(new { success = true, message = "Registro editado correctamente." }));
                }
                else
                {
                    return(Json(new { success = false, message = "Ha ocurrido un error. No se ha encontrado {0} {1} con el código especificado." }));
                }
            }
            catch (Exception exc)
            {
                string ErrorMsg = exc.GetBaseException().InnerException != null?exc.GetBaseException().InnerException.Message : exc.GetBaseException().Message;

                return(Json(new { success = false, message = "Error! " + ErrorMsg }));
            }
        }
Esempio n. 5
0
        public async Task <ActionResult> ForcePassword([FromBody] EditPasswordViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(Json(new { success = false, message = ErrorModelValidation.ShowError(new SerializableError(ModelState).Values) }));
            }

            try
            {
                var user  = _userManager.FindByIdAsync(model.Id).Result;
                var Token = await _userManager.GeneratePasswordResetTokenAsync(user);

                var result = await _userManager.ResetPasswordAsync(user, Token, model.Password);

                if (result.Succeeded)
                {
                    return(Json(new { success = true, message = "La contraseña se ha cambiado satisfactoriamente." }));
                }
                else
                {
                    string ErrorMsj = string.Concat(" - ", result.Errors.Select(x => x.Code));
                    return(Json(new { success = false, message = ErrorMsj }));
                }
            }
            catch (Exception excError)
            {
                return(Json(new { success = false, message = excError.Message }));
            }
        }
Esempio n. 6
0
        public async Task <IActionResult> CreateUser([FromBody] Register model)
        {
            if (!ModelState.IsValid)
            {
                return(Json(new { success = false, message = ErrorModelValidation.ShowError(new SerializableError(ModelState).Values) }));
            }

            try
            {
                var user = new ApplicationUser {
                    UserName = model.Cedula, Nombre = model.Nombre, Email = model.Email, PhoneNumber = model.Celular, Cedula = model.Cedula, Activo = true, IdCliente = model.IdCliente
                };
                var result = await _userManager.CreateAsync(user, model.Password);

                if (result.Succeeded)
                {
                    await AsignarRolAsync(_context, user, model.Roles);

                    _userManager.Dispose();
                    return(Json(new { success = true, message = "Usuario creado correctamente." }));
                }
                else
                {
                    string ErrorMsj = string.Concat(". ", result.Errors.Select(x => x.Code));
                    return(Json(new { success = false, message = ErrorMsj }));
                }
            }
            catch (Exception exc)
            {
                string ErrorMsg = exc.GetBaseException().InnerException != null?exc.GetBaseException().InnerException.Message : exc.GetBaseException().Message;

                return(Json(new { success = false, message = "Error!. " + ErrorMsg }));
            }
        }
Esempio n. 7
0
        public async Task <IActionResult> PutViaje([FromRoute] int id, [FromBody] Viaje Viaje)
        {
            if (!ModelState.IsValid)
            {
                return(Json(new { success = false, message = ErrorModelValidation.ShowError(new SerializableError(ModelState).Values) }));
            }

            try
            {
                if (Viaje.Id != id)
                {
                    return(Json(new { success = false, message = "No se pude editar el id del Registro" }));
                }

                //if (!Viaje.Activo)
                //{
                //    return Json(new { success = false, message = "No se pude editar un registro como inactivo" });
                //}

                LViaje.EditarViaje(Viaje, _context);
                return(Json(new { success = true, message = "Registro editado correctamente" }));
            }
            catch (Exception exc)
            {
                string ErrorMsg = exc.GetBaseException().InnerException != null?exc.GetBaseException().InnerException.Message : exc.GetBaseException().Message;

                return(Json(new { success = false, message = "Error!. " + ErrorMsg }));
            }
        }
        public async Task <IActionResult> CreateUser([FromBody] UserInfo model)
        {
            if (!ModelState.IsValid)
            {
                return(Json(new { success = false, message = ErrorModelValidation.ShowError(new SerializableError(ModelState).Values) }));
            }

            try
            {
                var user = new ApplicationUser {
                    UserName = model.PersonalId, Name = model.Name, Email = model.Email, PhoneNumber = model.PhoneNumber, PersonalID = model.PersonalId, Active = true
                };
                var result = await _userManager.CreateAsync(user, model.Password);

                if (result.Succeeded)
                {
                    _userManager.Dispose();
                    return(Json(new { success = true, message = "Usuario creado correctamente." }));
                }
                else
                {
                    string ErrorMsj = "";
                    result.Errors.ToList().ForEach(x => ErrorMsj += x.Code);
                    return(Json(new { success = false, message = ErrorMsj }));
                }
            }
            catch (Exception exc)
            {
                string ErrorMsg = exc.GetBaseException().InnerException != null?exc.GetBaseException().InnerException.Message : exc.GetBaseException().Message;

                return(Json(new { success = false, message = "Error!. " + ErrorMsg }));
            }
        }
        public async Task <IActionResult> PostCamion([FromBody] Camion Camion)
        {
            if (!ModelState.IsValid)
            {
                return(Json(new { success = false, message = ErrorModelValidation.ShowError(new SerializableError(ModelState).Values) }));
            }

            try
            {
                LCamion.GuardarCamion(Camion, _context);
                return(Json(new { success = true, message = "Camión guardado correctamente" }));
            }
            catch (Exception exc)
            {
                string ErrorMsg = exc.GetBaseException().InnerException != null?exc.GetBaseException().InnerException.Message : exc.GetBaseException().Message;

                return(Json(new { success = false, message = "Error!. " + ErrorMsg }));
            }
        }
        public async Task <ActionResult> ChangePassword([FromBody] ChangePasswordViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(Json(new { success = false, message = ErrorModelValidation.ShowError(new SerializableError(ModelState).Values) }));
            }

            try
            {
                string Id = User.getUserId();
                if (Id == null)
                {
                    return(Json(new { success = false, message = "Usuario no identificado, intente loguearse nuevamente." }));
                }

                var usuarioActual = _userManager.FindByIdAsync(Id).Result;

                if (usuarioActual != null)
                {
                    var result = await _userManager.ChangePasswordAsync(usuarioActual, model.OldPassword, model.NewPassword);

                    if (result.Succeeded)
                    {
                        return(Json(new { success = true, message = "Contraseña cambiada satisfactoriamente." }));
                    }
                    else
                    {
                        return(Json(new { success = false, message = "La contraseña antigua es incorrecta." }));
                    }
                }
                else
                {
                    return(Json(new { success = false, message = "El usuario no se encuentra logueado." }));
                }
            }
            catch (Exception exc)
            {
                string ErrorMsg = exc.GetBaseException().InnerException != null?exc.GetBaseException().InnerException.Message : exc.GetBaseException().Message;

                return(Json(new { success = false, message = ErrorMsg }));
            }
        }
Esempio n. 11
0
        public async Task <IActionResult> SaveMedicalAppointment([FromBody] MedicalAppointment entity)
        {
            if (!ModelState.IsValid)
            {
                return(Json(new { success = false, message = ErrorModelValidation.ShowError(new SerializableError(ModelState).Values) }));
            }

            try
            {
                entity.UserId = User.getUserId();
                entity.Active = true;
                LMedicalAppointment.SaveMedicalAppointment(entity, _repository, _IunitOfWork);
                return(Json(new { success = true, message = "Registro guardado correctamente." }));
            }
            catch (Exception exc)
            {
                string ErrorMsg = exc.GetBaseException().InnerException != null?exc.GetBaseException().InnerException.Message : exc.GetBaseException().Message;

                return(Json(new { success = false, message = "Error!. " + ErrorMsg }));
            }
        }
Esempio n. 12
0
        public async Task <IActionResult> GetUsers()
        {
            if (!ModelState.IsValid)
            {
                return(Json(new { success = false, message = ErrorModelValidation.ShowError(new SerializableError(ModelState).Values) }));
            }

            try
            {
                var Usuarios = _userManager.Users.ToList();
                // Es posible que se tenga que realizar un foreach para setear la propiedad Cliente a cada Usuario!
                List <Usuario> Users = Usuarios.Select(x => new Usuario {
                    Id = x.Id, Nombre = x.Nombre, Email = x.Email, Activo = x.Activo, NombreCliente = x.NombreCliente
                }).ToList();
                return(Json(new { success = true, message = Users }));
            }
            catch (Exception exc)
            {
                string ErrorMsg = exc.GetBaseException().InnerException != null?exc.GetBaseException().InnerException.Message : exc.GetBaseException().Message;

                return(Json(new { success = false, message = "Error!. " + ErrorMsg }));
            }
        }
Esempio n. 13
0
        public async Task <IActionResult> PutCamion([FromRoute] int id, [FromBody] Camion Camion)
        {
            if (!ModelState.IsValid)
            {
                return(Json(new { success = false, message = ErrorModelValidation.ShowError(new SerializableError(ModelState).Values) }));
            }

            try
            {
                if (Camion.Id != id)
                {
                    return(Json(new { success = false, message = "No se pude editar el id del Camión" }));
                }

                LCamion.EditarCamion(Camion, _context);
                return(Json(new { success = true, message = "Camión editado correctamente" }));
            }
            catch (Exception exc)
            {
                string ErrorMsg = exc.GetBaseException().InnerException != null?exc.GetBaseException().InnerException.Message : exc.GetBaseException().Message;

                return(Json(new { success = false, message = "Error!. " + ErrorMsg }));
            }
        }