public async Task <ActionResult> Asignarvendedor(string id, string idsupervisor) { try { var super = new SupervisorRequest { IdVendedor = Convert.ToInt32(id), IdSupervisor = Convert.ToInt32(idsupervisor) }; if (!string.IsNullOrEmpty(id)) { var response = await ApiServicio.ObtenerElementoAsync(super, new Uri(WebApp.BaseAddress), "api/Supervisor/Asignarvendedor"); if (response.IsSuccess) { InicializarMensaje(null); return(RedirectToAction("edit", new { id = idsupervisor })); } } } catch (Exception ex) { ex.ToString(); } return(View()); }
public async Task <ActionResult> Edit(string id) { try { var super = new SupervisorRequest { IdSupervisor = Convert.ToInt32(id) }; if (!string.IsNullOrEmpty(id)) { var response = await ApiServicio.ObtenerElementoAsync(super, new Uri(WebApp.BaseAddress), "api/Supervisor/obtenerSupervisor"); response.Resultado = JsonConvert.DeserializeObject <SupervisorRequest>(response.Resultado.ToString()); if (response.IsSuccess) { InicializarMensaje(null); return(View(response.Resultado)); } } } catch (Exception ex) { ex.ToString(); } return(View()); }
public async Task <ActionResult> Estadisticas() { try { InicializarMensaje(""); SupervisorRequest supervisorRequest = new SupervisorRequest(); int idEmpresaInt = 0; var userWithClaims = (ClaimsPrincipal)User; var idEmpresa = userWithClaims.Claims.First(c => c.Type == Constantes.Empresa).Value; idEmpresaInt = Convert.ToInt32(idEmpresa); supervisorRequest.IdEmpresa = idEmpresaInt; ApplicationDbContext db = new ApplicationDbContext(); Response response = new Response(); var userManager = new UserManager <ApplicationUser>(new UserStore <ApplicationUser>(db)); var idUsuarioActual = User.Identity.GetUserId(); supervisorRequest.IdUsuario = idUsuarioActual; supervisorRequest.IdEmpresa = idEmpresaInt; //metodo buscar supervisor response = await ApiServicio.ObtenerElementoAsync(supervisorRequest, new Uri(WebApp.BaseAddress), "api/Vendedores/obtenerSupervisorPorIdUsuario"); supervisorRequest = JsonConvert.DeserializeObject <SupervisorRequest>(response.Resultado.ToString()); supervisorRequest.IdSupervisor = supervisorRequest.IdSupervisor; var estadisticoVendedorRequest = await ApiServicio.ObtenerElementoAsync1 <EstadisticoSupervisorRequest>(supervisorRequest, new Uri(WebApp.BaseAddress), "api/Compromiso/VerEstadisticosPorSupervisor"); supervisorRequest.estadisticoSupervisorRequest = estadisticoVendedorRequest; return(View(supervisorRequest)); } catch { InicializarMensaje(Mensaje.Excepcion); return(View()); } }
public async Task <ActionResult> Edit(string id, SupervisorRequest supervisorRequest) { Response response = new Response(); ApplicationDbContext db = new ApplicationDbContext(); //VALIDA SI EXITE EL CORREO AL CREAR var userManager2 = new UserManager <ApplicationUser>(new UserStore <ApplicationUser>(db)); var InstanciaUsuario = await userManager2.FindByEmailAsync(supervisorRequest.Correo); if (InstanciaUsuario != null) { var super = new SupervisorRequest { IdSupervisor = Convert.ToInt32(id) }; response = await ApiServicio.ObtenerElementoAsync(super, new Uri(WebApp.BaseAddress), "api/Supervisor/obtenerSupervisor"); var MyUser = JsonConvert.DeserializeObject <SupervisorRequest>(response.Resultado.ToString()); if (MyUser.Correo != supervisorRequest.Correo) { InicializarMensaje(Mensaje.ExisteCorreo); return(View(response.Resultado)); } } //VALIDA SI EXITE LA IDENTIFICACION AL CREAR var ExisteUsuario = await ApiServicio.ObtenerElementoAsync1 <SupervisorRequest>(supervisorRequest, new Uri(WebApp.BaseAddress), "api/Supervisor/BuscarSupervisorPorEmpresaEIdentificacion"); if (ExisteUsuario != null) { var super = new SupervisorRequest { IdSupervisor = Convert.ToInt32(id) }; response = await ApiServicio.ObtenerElementoAsync(super, new Uri(WebApp.BaseAddress), "api/Supervisor/obtenerSupervisor"); var MyUser = JsonConvert.DeserializeObject <SupervisorRequest>(response.Resultado.ToString()); if (MyUser.Identificacion != supervisorRequest.Identificacion) { InicializarMensaje(Mensaje.ExisteIdentificacionUsuario); return(View(response.Resultado)); } } var userManager = new UserManager <ApplicationUser>(new UserStore <ApplicationUser>(db)); var user = db.Users.Find(supervisorRequest.IdUsuario); user.UserName = supervisorRequest.Correo; user.Email = supervisorRequest.Correo; user.Identificacion = supervisorRequest.Identificacion; user.Apellidos = supervisorRequest.Apellidos; user.Nombres = supervisorRequest.Nombres; user.Direccion = supervisorRequest.Direccion; user.Telefono = supervisorRequest.Telefono; var result = await userManager.UpdateAsync(user); db.SaveChanges(); if (result != null) { return(RedirectToAction("Index")); } return(View()); }
public async Task <ActionResult> Index() { //bUSCA LA EMPRESA var idEmpresaInt = 0; try { var userWithClaims = (ClaimsPrincipal)User; var idEmpresa = userWithClaims.Claims.First(c => c.Type == Constantes.Empresa).Value; idEmpresaInt = Convert.ToInt32(idEmpresa); } catch (Exception ex) { InicializarMensaje(Mensaje.ErrorIdEmpresa); return(View()); } //FIN SupervisorRequest supervisorRequest = new SupervisorRequest(); ApplicationDbContext db = new ApplicationDbContext(); var userManager = new UserManager <ApplicationUser>(new UserStore <ApplicationUser>(db)); var idUsuarioActual = User.Identity.GetUserId(); supervisorRequest.IdUsuario = idUsuarioActual; supervisorRequest.IdEmpresa = idEmpresaInt; if (userManager.IsInRole(idUsuarioActual, "GerenteGeneral")) { Response response = await ApiServicio.ObtenerElementoAsync(supervisorRequest, new Uri(WebApp.BaseAddress), "api/Vendedores/obtenerGerentePorIdUsuario"); supervisorRequest = JsonConvert.DeserializeObject <SupervisorRequest>(response.Resultado.ToString()); var userWithClaims = (ClaimsPrincipal)User; try { var lista = await ApiServicio.ObtenerElementoAsync1 <SupervisorRequest>(supervisorRequest, new Uri(WebApp.BaseAddress) , "api/Vendedores/ListarVendedoresGerente"); ViewBag.IdVendedor = new SelectList(lista.ListaVendedores, "IdVendedor", "NombreApellido"); var vista1 = new SupervisorRequest { FechaInicio = DateTime.Now, FechaFin = DateTime.Now, ListaVendedores = lista.ListaVendedores, Listarcompromiso = new List <CompromisoRequest>() }; return(View(vista1)); } catch (Exception ex) { ex.ToString(); return(View()); } } if (userManager.IsInRole(idUsuarioActual, "Supervisor")) { Response response = await ApiServicio.ObtenerElementoAsync(supervisorRequest, new Uri(WebApp.BaseAddress), "api/Vendedores/obtenerSupervisorPorIdUsuario"); supervisorRequest = JsonConvert.DeserializeObject <SupervisorRequest>(response.Resultado.ToString()); supervisorRequest.IdSupervisor = supervisorRequest.IdSupervisor; var userWithClaims = (ClaimsPrincipal)User; try { var lista = await ApiServicio.ObtenerElementoAsync1 <SupervisorRequest>(supervisorRequest, new Uri(WebApp.BaseAddress) , "api/Vendedores/ListarVendedoresSupervisor"); //var objeto = JsonConvert.DeserializeObject<SupervisorRequest>(lista.ListaVendedores.ToString()); ViewBag.IdVendedor = new SelectList(lista.ListaVendedores, "IdVendedor", "NombreApellido"); //var vista1 = new SupervisorRequest { FechaInicio = DateTime.Now, FechaFin = DateTime.Now, Listarcompromiso = new List<CompromisoRequest>() }; var vista1 = new SupervisorRequest { FechaInicio = DateTime.Now, FechaFin = DateTime.Now, ListaVendedores = lista.ListaVendedores, Listarcompromiso = new List <CompromisoRequest>() }; return(View(vista1)); } catch (Exception ex) { ex.ToString(); return(View()); } } var vista = new SupervisorRequest { FechaInicio = DateTime.Now, FechaFin = DateTime.Now, Listarcompromiso = new List <CompromisoRequest>() }; return(View(vista)); }