public async Task <ActionResult <UserPoster> > PostUserPoster(UserPoster userPoster) { _context.UserPosters.Add(userPoster); await _context.SaveChangesAsync(); return(CreatedAtAction("GetUserPoster", new { id = userPoster.Id }, userPoster)); }
public ActionResult RegistrarPoster(string message) { UserPoster userPoster = new UserPoster(); ViewBag.Message = message; return(View(userPoster)); }
public ActionResult Edit(int id) { UserPosterClient userPosterClient = new UserPosterClient(); UserPoster c = new UserPoster(); c = userPosterClient.Get(id); return(View("Edit", c)); }
public UserPoster Get(int id) { var result = new UserPoster(); try { result = _projectDbContext.UserPoster.Single(x => x.Id == id); }catch (Exception e) { } return(result); }
public ActionResult EditarPoster(int id, int idPais, int idCiudad, string correo, string empresa, string calle) { UserPoster userPoster = new UserPoster(); userPoster.Id = id; userPoster.NombrePais = idPais; userPoster.NombreCiudad = idCiudad; userPoster.Email = correo; userPoster.ConfirmarEmail = correo; userPoster.NombreCalle = calle; userPoster.NombreEmpresa = empresa; return(View("EditarPoster", userPoster)); }
public bool Add(UserPoster model) { try { _projectDbContext.UserPoster.Add(model); _projectDbContext.SaveChanges(); }catch (Exception e) { return(false); } return(true); }
public ActionResult Edit(UserPoster c) { UserPosterClient userPosterClient = new UserPosterClient(); if (ModelState.IsValid) { c.Email = c.Email.ToLower(); userPosterClient.Update(c); return(RedirectToAction("ProfileAcc")); } else { return(View(c)); } }
public ActionResult Create(PosterCreate posterCreate) { if (ModelState.IsValid) { string UserID = HttpContext.User.Identity.GetUserId(); Poster posterNew = new Poster { AddingDate = DateTime.Now, Title = posterCreate.Poster.Title, Price = posterCreate.Poster.Price, Views = 0, IsActive = posterCreate.Poster.IsActive, IsValuable = posterCreate.Poster.IsValuable, Content = posterCreate.Poster.Content, References = posterCreate.Poster.References, OwnerID = UserID }; _context.Posters.Add(posterNew); _context.SaveChanges(); UserPoster up = new UserPoster { ApplicationUserID = UserID, PosterID = posterNew.PosterID }; _context.UsersPosters.Add(up); _context.SaveChanges(); _context.Users.Where(x => x.Id == UserID).FirstOrDefault().UserPoster.Add(up); foreach (int categoryID in posterCreate.CategoriesID) { PosterCategory pc = new PosterCategory { CategoryID = categoryID, PosterID = posterNew.PosterID }; _context.PostersCategories.Add(pc); _context.SaveChanges(); posterNew.PostersCategories.Add(pc); _context.Categories.Where(x => x.CategoryID == categoryID).FirstOrDefault().PostersCategories.Add(pc); } _context.SaveChanges(); return(RedirectToAction("Index")); } return(View(posterCreate)); }
public ActionResult RegistrarPoster(UserPoster c) { UserPosterClient posterClient = new UserPosterClient(); if (ModelState.IsValid) { c.Email = c.Email.ToLower(); c.ConfirmarEmail = c.ConfirmarEmail.ToLower(); if (c.Email == c.ConfirmarEmail) { if (c.Contra == c.ConfirmarContra) { if (c.NombreCiudad == 0 || c.NombrePais == 0) { return(RegistrarPoster("Debes seleccionar un pais y su ciudad correspondiente.")); } else { if (posterClient.FindCorreo(c)) { return(RegistrarPoster("Ya existe una cuenta registrada con ese correo")); } else { posterClient.Add(c); return(RedirectToAction("Index")); } } } else { return(RegistrarPoster("Las Contraseñas no coinciden")); } } else { return(RegistrarPoster("Los Emails no coinciden")); } } else { return(View(c)); } }
public bool Update(UserPoster model) { try { var originalModel = _projectDbContext.UserPoster.Single(x => x.Id == model.Id); originalModel.Id = model.Id; originalModel.Contra = model.Contra; originalModel.Email = model.Email; originalModel.NombreCalle = model.NombreCalle; originalModel.NombreCiudad = model.NombreCiudad; originalModel.NombreEmpresa = model.NombreEmpresa; originalModel.NombrePais = model.NombrePais; _projectDbContext.Update(originalModel); _projectDbContext.SaveChanges(); }catch (Exception e) { return(false); } return(true); }
public async Task <IActionResult> PutUserPoster(UserPoster userPoster) { var original = await _context.UserPosters.FindAsync(userPoster.Id); if (original == null) { return(NotFound()); } original.NombreCalle = userPoster.NombreCalle; original.NombreCiudad = userPoster.NombreCiudad; original.NombreEmpresa = userPoster.NombreEmpresa; original.NombrePais = userPoster.NombrePais; original.Contra = userPoster.Contra; original.Email = userPoster.Email; _context.Entry(original).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!UserPosterExists(userPoster.Id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public ActionResult EditarPoster(UserPoster c) { UserPosterClient posterClient = new UserPosterClient(); var elemento = posterClient.Get(c.Id); if (ModelState.IsValid) { c.Email = c.Email.ToLower(); c.ConfirmarEmail = c.ConfirmarEmail.ToLower(); if (c.Email == c.ConfirmarEmail) { if (elemento.Contra == c.Contra) { if (c.NombreCiudad == 0 || c.NombrePais == 0) { return(EditarPoster("Debes seleccionar un pais y su ciudad correspondiente.")); } else { if (elemento.Email == c.Email) { posterClient.Update(c); if (User.IsInRole("Poster")) { return(RedirectToAction("Logout")); } else { return(RedirectToAction("GestionUserPoster", "UserAdmin")); } } else { if (posterClient.FindCorreo(c)) { return(EditarPoster("Ya existe una cuenta registrada con ese correo")); } else { posterClient.Update(c); if (User.IsInRole("Poster")) { return(RedirectToAction("Logout")); } else { return(RedirectToAction("GestionUserPoster", "UserAdmin")); } } } } } else { return(EditarPoster("Las Contraseñas no coinciden")); } } else { return(EditarPoster("Los Emails no coinciden")); } } else { return(View(c)); } }