예제 #1
0
 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);
     }
 }
예제 #2
0
 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");
     }
 }
예제 #3
0
 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);
     }
 }
예제 #4
0
 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");
     }
 }