public async Task <IHttpActionResult> GetEncargadoLogistica(int id) { EncargadoLogistica encargadoLogistica = await db.EncargadosLogistica.FindAsync(id); if (encargadoLogistica == null) { return(NotFound()); } return(Ok(encargadoLogistica)); }
// GET: EncargadosLogistica/Delete/5 public async Task <ActionResult> Delete(int?id) { EncargadoLogistica registro = new EncargadoLogistica(); if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } registro = await encargadosService.obtenerEncargadoLogistica(id); return(View(registro)); }
public async Task <IHttpActionResult> DeleteEncargadoLogistica(int id) { EncargadoLogistica encargadoLogistica = await db.EncargadosLogistica.FindAsync(id); if (encargadoLogistica == null) { return(NotFound()); } db.EncargadosLogistica.Remove(encargadoLogistica); await db.SaveChangesAsync(); return(Ok(encargadoLogistica)); }
public async Task <EncargadoLogistica> eliminarEncargadoLogistica(int?id) { using (HttpResponseMessage response = await Helpers.ConnectionHelper.httpClient.DeleteAsync(urlBase + id.ToString())) { if (response.IsSuccessStatusCode) { EncargadoLogistica registro = response.Content.ReadAsAsync <EncargadoLogistica>().Result; return(registro); } else { throw new Exception(response.ReasonPhrase); } } }
public async Task <EncargadoLogistica> adicionarEncargadoLogistica(EncargadoLogistica encargadologistica) { using (HttpResponseMessage response = await Helpers.ConnectionHelper.httpClient.PostAsJsonAsync(urlBase, encargadologistica)) { if (response.IsSuccessStatusCode) { EncargadoLogistica registro = response.Content.ReadAsAsync <EncargadoLogistica>().Result; return(registro); } else { throw new Exception(response.ReasonPhrase); } } }
public async Task <IHttpActionResult> PostEncargadoLogistica(EncargadoLogistica encargadoLogistica) { if (encargadoLogistica == null) { return(BadRequest("El modelo esta vacio")); } if (!ModelState.IsValid) { return(BadRequest(ModelState)); } db.EncargadosLogistica.Add(encargadoLogistica); await db.SaveChangesAsync(); return(CreatedAtRoute("DefaultApi", new { id = encargadoLogistica.Id }, encargadoLogistica)); }
public async Task <ActionResult> AddorEdit(EncargadoLogistica encargado) { if (encargado.Id == 0) { await encargadosService.adicionarEncargadoLogistica(encargado); TempData["SuccessMessage"] = "Saved Successfully"; } else { await encargadosService.modificarEncargadoLogistica(encargado.Id, encargado); TempData["SuccessMessage"] = "Updated Successfully"; } return(RedirectToAction("Index")); }
public async Task <IHttpActionResult> PutEncargadoLogistica(int id, EncargadoLogistica encargadoLogistica) { if (encargadoLogistica == null) { return(BadRequest("El modelo esta vacio")); } if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (encargadoLogistica.Id == 0 && id > 0) { encargadoLogistica.Id = id; } db.EncargadosLogistica.Attach(encargadoLogistica); db.Entry(encargadoLogistica).State = EntityState.Modified; foreach (var name in excluded) { db.Entry(encargadoLogistica).Property(name).IsModified = false; } try { await db.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!EncargadoLogisticaExists(id)) { return(NotFound()); } else { throw; } } EncargadoLogistica e = db.EncargadosLogistica.Find(id); return(Ok(e)); //return StatusCode(HttpStatusCode.NoContent); }
public async Task <ActionResult> AddorEdit(int id = 0) { List <Usuario> usuarios; usuarios = await usuariosService.obtenerUsuarios(); usuarios = usuarios.Where(x => x.RolId == 2).ToList(); ViewBag.UsuariosListItems = usuarios; if (id == 0) { return(View(new EncargadoLogistica())); } else { EncargadoLogistica encargado = await encargadosService.obtenerEncargadoLogistica(id); return(View(encargado)); } }
public IHttpActionResult IniciarSesion([FromBody] LoginRequest model) { List <Usuario> usuarios = db.Usuarios.ToList(); try { var usuarioa = usuarios.FirstOrDefault(x => x.NombreUsuario == model.Username); Usuario usuario = usuarios.FirstOrDefault(x => x.NombreUsuario == model.Username && x.Contrasena == model.Password); if (usuario != null) { List <EncargadoLogistica> encargados = db.EncargadosLogistica.ToList(); List <Repartidor> repartidores = db.Repartidores.ToList(); EncargadoLogistica encargado = encargados.FirstOrDefault(x => x.UsuarioId == usuario.Id); Repartidor repartidor = repartidores.FirstOrDefault(x => x.UsuarioId == usuario.Id); if (encargado != null) { LoginResponse res = new LoginResponse(); var token = new TokenResponse(); using (HttpClient httpClient = new HttpClient()) { HttpContent content = new FormUrlEncodedContent(new[] { new KeyValuePair <string, string>("grant_type", "password"), new KeyValuePair <string, string>("username", usuario.NombreUsuario), new KeyValuePair <string, string>("password", usuario.Contrasena) }); //HttpResponseMessage result = httpClient.PostAsync("http://localhost/MonitoreoLogisticoService/token", content).Result; HttpResponseMessage result = httpClient.PostAsync("http://localhost:5757/token", content).Result; var resultContent = result.Content.ReadAsStringAsync().Result; token = JsonConvert.DeserializeObject <TokenResponse>(resultContent); res.NombreCompleto = encargado.NombreCompleto; res.Email = encargado.Email; res.EncargadoId = encargado.Id; res.Token = token.access_token; var json = JToken.FromObject(res); return(Ok(json)); } } else { if (repartidor != null) { LoginResponse res = new LoginResponse(); var token = new TokenResponse(); using (HttpClient httpClient = new HttpClient()) { HttpContent content = new FormUrlEncodedContent(new[] { new KeyValuePair <string, string>("grant_type", "password"), new KeyValuePair <string, string>("username", usuario.NombreUsuario), new KeyValuePair <string, string>("password", usuario.Contrasena) }); //HttpResponseMessage result = httpClient.PostAsync("http://localhost/MonitoreoLogisticoService/token", content).Result; HttpResponseMessage result = httpClient.PostAsync("http://localhost:5757/token", content).Result; var resultContent = result.Content.ReadAsStringAsync().Result; token = JsonConvert.DeserializeObject <TokenResponse>(resultContent); res.NombreCompleto = repartidor.NombreCompleto; res.Email = repartidor.Email; res.EncargadoId = repartidor.Id; res.Token = token.access_token; var json = JToken.FromObject(res); return(Ok(json)); } } } } } catch (Exception e) { var a = e.Message; } return(BadRequest()); }