public static void Delete(Noticias pNoticias) { DataBase db = GetDataBase(); var query = from c in db.Noticia where c.Id == pNoticias.Id select c; db.Noticia.DeleteOnSubmit(query.ToList()[0]); db.SubmitChanges(); }
private void addFav_Click(object sender, EventArgs e) { if (noticia != null) { Noticias noticias = new Noticias { Title = noticia.Title, PubDate = noticia.PubDate, Link = noticia.Link }; NoticiasRepository.Create(noticia); if (MessageBox.Show("Adicionado com sucesso!") == MessageBoxResult.OK) { } } else { if (MessageBox.Show("Você deve selecionar uma noticia primeiro!") == MessageBoxResult.OK) { } } }
private void onSelecionChange(object sender, SelectionChangedEventArgs e) { noticia = null; noticia = (sender as ListBox).SelectedItem as Noticias; }
public static void Create(Noticias pNoticias) { DataBase db = GetDataBase(); db.Noticia.InsertOnSubmit(pNoticias); db.SubmitChanges(); }
public ActionResult Create(Noticias noticias, HttpPostedFileBase audio, HttpPostedFileBase foto, int[] TagsIds) { if (ModelState.IsValid) { noticias.dataCadastro = DateTime.Now; noticias.dataAtualizacao = DateTime.Now; noticias.transito = true; db.Noticias.Add(noticias); if (TagsIds != null) { noticias.Tags = new List <Tags>(); foreach (var tagId in TagsIds) { var tag = db.Tags.Find(tagId); noticias.Tags.Add(tag); } } if (db.SaveChanges() > 0) { #region uploads if (foto != null) { var path700x460 = Server.MapPath(string.Format(pathFoto700x460, noticias.id)); var path620x415 = Server.MapPath(string.Format(pathFoto620x415, noticias.id)); var path620x200 = Server.MapPath(string.Format(pathFoto620x200, noticias.id)); var path300x200 = Server.MapPath(string.Format(pathFoto300x200, noticias.id)); var path93x93 = Server.MapPath(string.Format(pathFoto93x93, noticias.id)); var fileOriginal = Server.MapPath(string.Format(pathOriginal, noticias.id)); noticias.foto = Utils.SaveFileBase(fileOriginal, foto); Utils.SaveFileBase(path93x93, foto, noticias.foto); noticias.fotoMini = noticias.foto; Utils.SaveAndCropImage(foto, path700x460, 0, 0, 700, 460, true, noticias.foto); Utils.SaveAndCropImage(foto, path620x415, 0, 0, 620, 415, true, noticias.foto); Utils.SaveAndCropImage(foto, path620x200, 0, 0, 620, 200, true, noticias.foto); Utils.SaveAndCropImage(foto, path300x200, 0, 0, 300, 200, true, noticias.foto); if (!Directory.Exists(path93x93)) { Directory.CreateDirectory(path93x93); } Utils.resizeImageAndSave(path300x200 + noticias.foto, 93, 93, path93x93); } ; int suffix = 0; do { noticias.url = noticias.titulo.GenerateSlug() + (suffix > 0 ? suffix.ToString() : ""); suffix++; } while (db.Noticias.Where(o => o.url == noticias.url).Count() > 0); if (audio != null) { var path = Server.MapPath("~/conteudo/noticias/" + noticias.id + "/audio/"); noticias.audio = Utils.SaveFileBase(path, audio); } db.Entry(noticias).State = EntityState.Modified; db.SaveChanges(); #endregion } return(RedirectToAction("Index")); } ViewBag.CategoriaMapaId = new SelectList(db.CategoriasMapa.Where(a => !a.Excluido), "Id", "Titulo", noticias.CategoriaMapaId); ViewBag.idColunista = new SelectList(db.Colunista.Where(a => !a.excluido), "id", "nome", noticias.idColunista); ViewBag.idGaleria = new SelectList(db.Galeria.Where(a => !a.excluido && !a.Fixa).OrderByDescending(a => a.dataCadastro), "id", "titulo", noticias.idGaleria); ViewBag.RegiaoId = new SelectList(db.NoticiasRegioes.Where(a => !a.Excluido), "Id", "Titulo", noticias.RegiaoId); ViewBag.MultiSelectTags = new MultiSelectList(db.Tags.Where(a => !a.Excluido), "Id", "Titulo"); return(View(noticias)); }
public ActionResult Edit(Noticias noticias, HttpPostedFileBase audioUpload, HttpPostedFileBase fotoUpload, int[] EditoriaId, string ListaTags = "", string fotoExistente = "") { if (!string.IsNullOrEmpty(fotoExistente)) { noticias.foto = fotoExistente; ModelState.Remove("fotoUpload"); } if (audioUpload != null && !audioUpload.IsExtension("mp3", "aac")) { ModelState.AddModelError("audio", "A extensão do áudio deve ser apenas nos formatos: .mp3 e .aac ."); } if ((fotoUpload == null && string.IsNullOrWhiteSpace(noticias.foto)) && (noticias.TipoDestaque.Value == (int)TipoDestaque.Normal1 || noticias.TipoDestaque.Value == (int)TipoDestaque.Normal2 || noticias.TipoDestaque.Value == (int)TipoDestaque.Normal3 || noticias.TipoDestaque.Value == (int)TipoDestaque.Urgente1130 || noticias.TipoDestaque.Value == (int)TipoDestaque.Urgente360)) { ModelState.AddModelError("TipoDestaque", "A notícia deve ter uma foto para poder ser colocada em destaque."); } else if (ModelState.IsValid) { if (!string.IsNullOrEmpty(noticias.videoYoutube)) { if (noticias.videoYoutube.Contains("=")) { string[] keyYoutube = noticias.videoYoutube.Split(new char[] { '=' }); noticias.videoYoutube = keyYoutube[1]; } } #region uploads if (fotoUpload != null) { var path744x500 = Server.MapPath(string.Format(pathFoto744x500, noticias.id)); var path405x270 = Server.MapPath(string.Format(pathFoto405x270, noticias.id)); var path365x240 = Server.MapPath(string.Format(pathFoto365x240, noticias.id)); var path260x173 = Server.MapPath(string.Format(pathFoto260x173, noticias.id)); var fileOriginal = Server.MapPath(string.Format(pathOriginal, noticias.id)); noticias.foto = Utils.SaveFileBase(fileOriginal, fotoUpload); noticias.fotoMini = noticias.foto; Utils.resizeImageAndSave3(Path.Combine(fileOriginal, noticias.foto), 744, 500, path744x500); Utils.resizeImageAndSave3(Path.Combine(fileOriginal, noticias.foto), 405, 270, path405x270); Utils.resizeImageAndSave3(Path.Combine(fileOriginal, noticias.foto), 365, 240, path365x240); Utils.resizeImageAndSave3(Path.Combine(fileOriginal, noticias.foto), 260, 173, path260x173); } int suffix = 0; do { noticias.url = (!string.IsNullOrWhiteSpace(noticias.chamada) ? noticias.chamada.GenerateSlug() : !string.IsNullOrWhiteSpace(noticias.TituloCapa) ? noticias.TituloCapa.GenerateSlug() : noticias.titulo.GenerateSlug()) + (suffix > 0 ? suffix.ToString() : ""); suffix++; } while (db.Noticias.Where(o => o.url == noticias.url && o.id != noticias.id).Count() > 0); if (audioUpload != null) { var path = Server.MapPath("~/conteudo/noticias/" + noticias.id + "/audio/"); noticias.audio = Utils.SaveFileBase(path, audioUpload); } var bdDataAtualizacao = db.Noticias.AsNoTracking().FirstOrDefault(noticia => noticia.id == noticias.id).dataAtualizacao; //noticias.dataAtualizacao = DateTime.Now; if (noticias.dataAtualizacao == null || bdDataAtualizacao == noticias.dataAtualizacao) { noticias.dataAtualizacao = DateTime.Now; } db.Entry(noticias).State = EntityState.Modified; db.SaveChanges(); #endregion #region Tags db.Entry(noticias).Collection("Tags").Load(); noticias.Tags.Clear(); if (!string.IsNullOrEmpty(ListaTags)) { noticias.Tags = new List <Tags>(); string[] tags = ListaTags.Split(new char[] { ',' }); foreach (var item in tags) { var hasTag = db.Tags.FirstOrDefault(x => x.Titulo.ToLower() == item.ToLower()); if (hasTag != null) { noticias.Tags.Add(hasTag); } else { var obj = new Tags { chave = item.GenerateSlug(), DataCadastro = DateTime.Now, Excluido = false, Titulo = item }; db.Tags.Add(obj); db.SaveChanges(); noticias.Tags.Add(obj); } } } #endregion #region Editoriais if (EditoriaId.Count() > 0) { db.Entry(noticias).Collection("Editoriais").Load(); noticias.Editoriais.Clear(); foreach (var id in EditoriaId) { int idEditorial = Convert.ToInt32(id); var editorial = db.Editoriais.FirstOrDefault(x => x.id == id); if (editorial != null) { noticias.Editoriais.Add(editorial); } } } #endregion db.Entry(noticias).State = EntityState.Modified; db.Database.Log = m => Log(m); db.SaveChanges(); Site.Services.RedisService.FlushAll(noticias.url); Site.Services.RedisService.FlushAll(noticias.id.ToString()); GerenciaLogs.saveLog(ref db, WebSecurity.GetUserId(User.Identity.Name), areaADM, TipoAcesso.Edicao, noticias.id); return(RedirectToAction("Index")); } foreach (var item in EditoriaId) { int idEditorial = Convert.ToInt32(item); var editorial = db.Editoriais.FirstOrDefault(x => x.id == item); if (editorial != null) { noticias.Editoriais.Add(editorial); } } ViewBag.CategoriaMapaId = new SelectList(db.CategoriasMapa.Where(a => !a.Excluido), "Id", "Titulo", noticias.CategoriaMapaId); ViewBag.idColunista = new SelectList(db.Colunista.Where(a => !a.excluido), "id", "nome", noticias.idColunista); ViewBag.idGaleria = new SelectList(db.Galeria.Where(a => !a.excluido && !a.Fixa).OrderByDescending(a => a.dataCadastro), "id", "titulo", noticias.idGaleria); ViewBag.RegiaoId = new SelectList(db.NoticiasRegioes.Where(a => !a.Excluido), "Id", "Titulo", noticias.RegiaoId); ViewBag.TiposDestaques = (from Enum item in Enum.GetValues(typeof(TipoDestaque)) select new SelectListItem { Value = ((int)(object)item).ToString(), Text = item.GetDescription() }).ToList(); var times = db.Times.Where(time => time.Ativo && !time.Excluido); var editoriais = db.Editoriais.Where(a => !a.excluido && a.ativo && a.esportes && a.id != 1 && !times.Any(time => time.EditoriaId == a.id)); ViewBag.AutoCompleteTags = db.Tags.Where(a => !a.Excluido).Select(x => x.Titulo).ToArray(); var tagsNoticia = noticias.Tags.Select(x => x.Titulo).ToArray(); var editoriaIds = noticias.Editoriais.Select(editoria => editoria.id).ToArray(); ViewBag.Times = times.Select(time => new SelectListItem { Value = time.EditoriaId.ToString(), Text = time.Nome, Selected = editoriaIds.Any(editoria => editoria == time.EditoriaId) }).ToList(); ViewBag.Campeonatos = editoriais.Select(editorial => new SelectListItem { Value = editorial.id.ToString(), Text = editorial.nome, Selected = editoriaIds.Any(editoria => editoria == editorial.id) }).ToList(); ViewBag.tagsNoticia = ListaTags; return(View(noticias)); }
public void ComentarNoticia(Noticias N) { FabricaPersistencia.getPNoticia().ComentarNoticia(N); }
public void Modificar(Noticias N, Administrador adminBD) { FabricaPersistencia.getPNoticia().Modificar(N, adminBD); }
public void Baja(Noticias N, Administrador adminBD) { FabricaPersistencia.getPNoticia().Baja(N, adminBD); }