public NombreAnunciosDTO Find(int?id) { try { //Mapeo de clase NombreAnuncios model = db.NombreAnuncios.Include(x => x.caracteristicas).Include(x => x.noIncluidas).FirstOrDefault(x => x.id == id); NombreAnunciosDTO response = new NombreAnunciosDTO(); response.id = model.id; response.nombre = model.nombre; model.caracteristicas.ForEach(x => { CaracteristicasDTO item = new CaracteristicasDTO(); item.nombre = x.nombre; item.id = x.id; response.caracteristicas.Add(item); }); model.noIncluidas.ForEach(x => { CaracteristicasDTO item = new CaracteristicasDTO(); item.nombre = x.nombre; item.id = x.id; response.noIncluidas.Add(item); }); return(response); } catch (Exception) { throw; } }
public List <CaracteristicasDTO> getCaracteristicasByID(int id) { try { NombreAnunciosDTO nombre = Find(id); List <CaracteristicasDTO> response = nombre.caracteristicas; return(response); } catch (Exception) { throw; } }
// GET: ConfiguracionEmpresa/RazonesSociales/Delete/5 public ActionResult DeleteItem(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } NombreAnunciosDTO nombreAnuncio = nombreAnunciosDAO.Find(id); if (nombreAnuncio == null) { return(HttpNotFound()); } return(PartialView("Delete", nombreAnuncio)); }
public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } NombreAnunciosDTO peridos = nombreAnunciosDAO.Find(id); if (peridos == null) { return(HttpNotFound()); } return(PartialView(peridos)); }
public NombreAnunciosDTO Add(string nombre, List <string> dataList) { try { NombreAnunciosDTO model = new NombreAnunciosDTO(); model.nombre = nombre; List <CaracteristicasDTO> caracteristicas = caracteristicasDAO.getList(); dataList.ForEach(x => { caracteristicas.ForEach(y => { if (x == y.id.ToString()) { model.caracteristicas.Add(y); } }); }); model.noIncluidas = caracteristicas.Except(model.caracteristicas).ToList(); //var remove = model.noIncluidas.FirstOrDefault(x => x.nombre.Equals("Imagen")); //model.noIncluidas.Remove(remove); //Mapeo de clase NombreAnuncios response = new NombreAnuncios(); response.nombre = model.nombre; model.caracteristicas.ForEach(x => { Caracteristicas item = new Caracteristicas(); item.nombre = x.nombre; item.id = x.id; response.caracteristicas.Add(item); }); model.noIncluidas.ForEach(x => { Caracteristicas item = new Caracteristicas(); item.nombre = x.nombre; item.id = x.id; response.noIncluidas.Add(item); }); db.NombreAnuncios.Add(response); db.SaveChanges(); ViewInfoMensaje.setMensaje(controller, MensajeBuilder.CrearMsgSuccess(entidad), Helpers.InfoMensajes.ConstantsLevels.SUCCESS); return(model); } catch (Exception) { throw; } }
public List <NombreAnunciosDTO> getList() { try { List <NombreAnuncios> periodosModel = db.NombreAnuncios.Where(x => x.estado == true).ToList(); List <NombreAnunciosDTO> responseList = new List <NombreAnunciosDTO>();; periodosModel.ForEach(x => { NombreAnunciosDTO response = new NombreAnunciosDTO(); response.id = x.id; response.nombre = x.nombre; x.caracteristicas.ForEach(y => { CaracteristicasDTO item = new CaracteristicasDTO(); item.nombre = x.nombre; item.id = x.id; response.caracteristicas.Add(item); }); x.noIncluidas.ForEach(y => { CaracteristicasDTO item = new CaracteristicasDTO(); item.nombre = x.nombre; item.id = x.id; response.noIncluidas.Add(item); }); responseList.Add(response); }); return(responseList); } catch (Exception) { throw; } }
public ActionResult EditItem(int id, string nombre, List <string> dataList) { NombreAnunciosDTO nombreAnuncios = nombreAnunciosDAO.Update(id, nombre, dataList); return(PartialView("Confirm", nombreAnuncios)); }
public ActionResult CreateNew(string nombre, List <string> dataList) { NombreAnunciosDTO nombreAnuncio = nombreAnunciosDAO.Add(nombre, dataList); return(PartialView("Confirm", nombreAnuncio)); }
public NombreAnunciosDTO Update(int id, string nombre, List <string> dataList) { NombreAnunciosDTO model = new NombreAnunciosDTO(); try { model.nombre = nombre; List <CaracteristicasDTO> caracteristicas = caracteristicasDAO.getList(); dataList.ForEach(x => { caracteristicas.ForEach(y => { if (x == y.id.ToString()) { model.caracteristicas.Add(y); } }); }); model.noIncluidas = caracteristicas.Except(model.caracteristicas).ToList(); //Mapeo de clase NombreAnuncios response = db.NombreAnuncios.Include(x => x.caracteristicas).Include(x => x.noIncluidas).First(x => x.id == id); response.nombre = model.nombre; if (response.caracteristicas.Count == 0) { model.caracteristicas.ForEach(y => { Caracteristicas item = new Caracteristicas(); item.nombre = y.nombre; item.id = y.id; response.caracteristicas.Add(item); }); } else { response.caracteristicas.Clear(); model.caracteristicas.ForEach(y => { Caracteristicas item = new Caracteristicas(); item.nombre = y.nombre; item.id = y.id; response.caracteristicas.Add(item); }); } if (response.noIncluidas.Count == 0) { model.noIncluidas.ForEach(y => { Caracteristicas item = new Caracteristicas(); item.nombre = y.nombre; item.id = y.id; response.noIncluidas.Add(item); }); } else { response.noIncluidas.Clear(); model.noIncluidas.ForEach(x => { Caracteristicas item = new Caracteristicas(); item.nombre = x.nombre; item.id = x.id; response.noIncluidas.Add(item); }); } db.Entry(response).State = EntityState.Modified; db.SaveChanges(); model = Find(id); ViewInfoMensaje.setMensaje(controller, MensajeBuilder.EditarMsgSuccess(entidad), Helpers.InfoMensajes.ConstantsLevels.SUCCESS); return(model); } catch (Exception) { ViewInfoMensaje.setMensaje(controller, MensajeBuilder.EditarMsgError(entidad), Helpers.InfoMensajes.ConstantsLevels.ERROR); return(model); } }