// // GET: /Anuncios/ public List<Anuncio> GetAnuncios() { AnunciosDbContext contextoAnuncios = new AnunciosDbContext(); List<Anuncio> anunciosExistentes = contextoAnuncios.anuncios.Include(d => d.categoria). Include(d => d.ciudad).ToList(); return anunciosExistentes; }
public List<Anuncio> ObtenerAnunciosUser(String username) { AnunciosDbContext contextoAnuncios = new AnunciosDbContext(); List<Anuncio> anunciosUser = contextoAnuncios.anuncios.Include(d => d.categoria). Include(d => d.ciudad).Include(d => d.anunciante).ToList().FindAll(a => a.anunciante.UserName.Equals(username)); return anunciosUser; }
public Anuncio GetAnuncio(int id) { AnunciosDbContext contextoAnuncios = new AnunciosDbContext(); Anuncio detalleAnuncio = contextoAnuncios.anuncios.Include(d => d.categoria). Include(d => d.ciudad).Include(d => d.anunciante).First(d => d.anuncioId.Equals(id)); return detalleAnuncio; }
public List<Anuncio> FiltrarAnuncios(int categoria, int ciudad) { AnunciosDbContext contextoAnuncios = new AnunciosDbContext(); List<Anuncio> anunciosExistentes = contextoAnuncios.anuncios.Include(d => d.categoria). Include(d => d.ciudad).ToList(); //Filtramos en función a la cateogría y la ciudad. List<Anuncio> anunciosFiltrados = anunciosExistentes .FindAll(a => a.categoriaId.Equals(categoria)) .FindAll(a => a.ciudadId.Equals(ciudad)); return anunciosFiltrados; }
public static List<SelectListItem> cargarCategoriasExistentes() { List<SelectListItem> categoriasExistentes = new List<SelectListItem>(); AnunciosDbContext db = new AnunciosDbContext(); List<Categorias> categoriasBBDD = db.categorias.ToList(); foreach (Categorias c in categoriasBBDD) { SelectListItem temp = new SelectListItem(); temp.Text = c.nombre; temp.Value = c.categoriaId.ToString(); categoriasExistentes.Add(temp); } return categoriasExistentes; }
public static List<SelectListItem> cargarCiudadesExistentes() { List<SelectListItem> ciudadesDisponibles = new List<SelectListItem>(); AnunciosDbContext db = new AnunciosDbContext(); List<Ciudades> ciudadesExistentes = db.ciudades.ToList(); foreach (Ciudades c in ciudadesExistentes) { SelectListItem ciudad = new SelectListItem(); ciudad.Value = c.ciudadId.ToString(); ciudad.Text = c.nombre; ciudadesDisponibles.Add(ciudad); } return ciudadesDisponibles; }
public ActionResult Publicar() { AnunciosDbContext db = new AnunciosDbContext(); AnuncioRegistro modelo = new AnuncioRegistro(); modelo.categoriasDisponibles = CargadorSelectItems.cargarCategoriasExistentes(); //Cargamos unicamente la ciudad del usuario, ya que no puede publicar anuncios en otras ciudades. UserProfile perfil = db.usuarios.FirstOrDefault(d => d.UserName.Equals(User.Identity.Name)); modelo.ciudadId = perfil.ciudadId; SelectListItem ciudadUsuario = new SelectListItem(); ciudadUsuario.Text = db.ciudades.First(d => d.ciudadId.Equals(perfil.ciudadId)).nombre; ciudadUsuario.Value = perfil.ciudadId.ToString(); List<SelectListItem> ciudadesUsuario = new List<SelectListItem>(); ciudadesUsuario.Add(ciudadUsuario); modelo.ciudadesUsuario = ciudadesUsuario; return View(modelo); }
public ActionResult ChangePersonalInfo(ManagementModel model) { if (ModelState.IsValid) { AnunciosDbContext db = new AnunciosDbContext(); UserProfile perfil = db.usuarios.FirstOrDefault(d => d.UserName.Equals(User.Identity.Name)); perfil.Nombre = model.infoPersonal.Nombre; perfil.Apellidos = model.infoPersonal.Apellidos; perfil.Email = model.infoPersonal.Email; perfil.ciudadId = model.infoPersonal.CiudadId; db.SaveChanges(); return RedirectToAction("Manage", new { Message = ManageMessageId.ChangePersonalInfoSuccess }); } else { return RedirectToAction("Manage"); } }
public HttpResponseMessage DeleteAnuncio(int id) { if (ModelState.IsValid) { if (User.Identity.IsAuthenticated) { AnunciosDbContext db = new AnunciosDbContext(); Anuncio anuncioABorrar = db.anuncios.Find(id); db.anuncios.Remove(anuncioABorrar); db.SaveChanges(); return new HttpResponseMessage(HttpStatusCode.OK); } else { return new HttpResponseMessage(HttpStatusCode.Forbidden); } } else { return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState); } }
public ActionResult AddCategory(AdminModel modelo) { if (ModelState.IsValid) { AnunciosDbContext db = new AnunciosDbContext(); List<Categorias> categoriasBBDD = db.categorias.ToList(); if (categoriasBBDD.Exists(d => d.nombre.ToLower().Equals(modelo.modeloRegistro.nombreNuevaCategoria.ToLower()))) { return RedirectToAction("Admin", new { statusMessage = StatusMessages.CategoriaExistente }); } else { Categorias nuevaCategoria = new Categorias(); nuevaCategoria.nombre = modelo.modeloRegistro.nombreNuevaCategoria; db.categorias.Add(nuevaCategoria); db.SaveChanges(); return RedirectToAction("Admin", new { statusMessage = StatusMessages.CategoriaAgregada }); } } else { return RedirectToAction("Admin"); } }
public HttpResponseMessage PostAnuncio(AnuncioRegistro anuncio) { if (ModelState.IsValid) { AnunciosDbContext db = new AnunciosDbContext(); Anuncio anuncioDb = new Anuncio(); anuncioDb.categoriaId = anuncio.categoriaId; anuncioDb.ciudadId = anuncio.ciudadId; anuncioDb.descripcion = anuncio.descripcion; anuncioDb.titulo = anuncio.titulo; anuncioDb.precioHora = Convert.ToDecimal(anuncio.precioHora); anuncioDb.userId = db.usuarios.FirstOrDefault(d => d.UserName.Equals(User.Identity.Name)).UserId; db.anuncios.Add(anuncioDb); db.SaveChanges(); return new HttpResponseMessage(HttpStatusCode.OK); } else { return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState); } }
// // GET: /Account/Manage public ActionResult Manage(ManageMessageId? message) { ViewBag.StatusMessage = message == ManageMessageId.ChangePasswordSuccess ? "Tu contraseña ha sido cambiada." : message == ManageMessageId.ChangePersonalInfoSuccess ? "Se ha actualizado tu información personal." : message == ManageMessageId.ChangePasswordFail ? "Se ha producido un error al cambiar la contraseña." : ""; ViewBag.HasLocalPassword = OAuthWebSecurity.HasLocalAccount(WebSecurity.GetUserId(User.Identity.Name)); ViewBag.ReturnUrl = Url.Action("Manage"); //Cargamos la información personal del usuario ManagementModel modelo = new ManagementModel(); PersonalInfoModel infoExistente = new PersonalInfoModel(); AnunciosDbContext db = new AnunciosDbContext(); UserProfile perfil = db.usuarios.FirstOrDefault(d => d.UserName.Equals(User.Identity.Name)); infoExistente.Nombre = perfil.Nombre; infoExistente.Apellidos = perfil.Apellidos; infoExistente.Email = perfil.Email; infoExistente.CiudadId = perfil.ciudadId; infoExistente.ciudadesDisponibles = CargadorSelectItems.cargarCiudadesExistentes(); infoExistente.ciudadesDisponibles.First(d => d.Value.Equals(infoExistente.CiudadId.ToString())).Selected = true; modelo.infoPersonal = infoExistente; return View(modelo); }