public ActionResult Create(Galeria galeria) { if (ModelState.IsValid) { galeria.excluido = false; galeria.dataCadastro = DateTime.Now; int suffix = 0; do { galeria.chave = galeria.titulo.GenerateSlug() + (suffix > 0 ? (suffix++).ToString() : ""); suffix++; } while (db.Materia.Where(o => o.chave == galeria.chave).Count() > 0); db.Galeria.Add(galeria); db.SaveChanges(); GerenciaLogs.saveLog(ref db, WebSecurity.GetUserId(User.Identity.Name), areaADM, TipoAcesso.Insercao, galeria.id); return(RedirectToAction("Edit", new { id = galeria.id })); } return(View(galeria)); }
public ActionResult VideosCreate(BastidoresMidias dados) { if (ModelState.IsValid) { if (dados.midia.Contains("=")) { string[] keyYoutube = dados.midia.Split(new char[] { '=' }); dados.midia = keyYoutube[1]; } dados.excluido = false; dados.video = true; dados.dataCadastro = DateTime.Now; db.BastidoresMidias.Add(dados); db.SaveChanges(); GerenciaLogs.saveLog(ref db, WebSecurity.GetUserId(User.Identity.Name), areaADM2, TipoAcesso.Insercao, dados.id); return(RedirectToAction("VideosDetails", new { id = dados.id })); } return(View(dados)); }
public ActionResult Edit(Editoriais editoriais) { if (ModelState.IsValid) { int suffix = 0; do { editoriais.chave = editoriais.nome.GenerateSlug() + (suffix > 0 ? (suffix++).ToString() : ""); suffix++; } while (db.Editoriais.Where(o => o.chave == editoriais.chave && o.id != editoriais.id).Count() > 0); db.Entry(editoriais).State = EntityState.Modified; db.Entry(editoriais).Property("DataCadastro").IsModified = false; db.SaveChanges(); GerenciaLogs.saveLog(ref db, WebSecurity.GetUserId(User.Identity.Name), areaADM, TipoAcesso.Edicao, editoriais.id); return(RedirectToAction("Index")); } return(View(editoriais)); }
public ActionResult Create(NoticiasPADs noticia, HttpPostedFileBase logo, int cropX = 0, int cropY = 0, int cropWidth = 0, int cropHeight = 0) { Validacao(noticia); if (ModelState.IsValid) { noticia.Excluido = false; noticia.DataCadastro = DateTime.Now; db.NoticiasPADs.Add(noticia); if (db.SaveChanges() > 0 && logo != null) { #region uploads var fileOriginal = Server.MapPath(string.Format(pathOriginal, noticia.Id)); if (cropWidth > 0 && cropHeight > 0) { noticia.Foto = Utils.SaveAndCropColunista(logo, fileOriginal, cropX, cropY, cropWidth, cropHeight); } else { noticia.Foto = Utils.SaveFileBase(fileOriginal, logo); } db.Entry(noticia).State = EntityState.Modified; db.SaveChanges(); #endregion } GerenciaLogs.saveLog(ref db, WebSecurity.GetUserId(User.Identity.Name), areaADM, TipoAcesso.Insercao, noticia.Id); return(RedirectToAction("Details", new { id = noticia.Id })); } ApoioViewBag(noticia); return(View(noticia)); }
public ActionResult DeleteConfirmed(int id) { Programacao programacao = db.Programacao.Find(id); db.Entry(programacao).State = EntityState.Modified; db.Entry(programacao).Collection("Apresentadores").Load(); db.Entry(programacao).Collection("Horario_programacao").Load(); db.Entry(programacao).Collection("Materia").Load(); List <Horario_programacao> horasAntigas = db.Horario_programacao.Where(x => x.idPrograma == programacao.id).ToList(); foreach (var horaAntiga in horasAntigas) { db.Horario_programacao.Remove(horaAntiga); } List <Materia> MateriaAntigas = db.Materia.Where(x => x.idProgramacao == programacao.id).ToList(); foreach (var materiaAntiga in MateriaAntigas) { materiaAntiga.excluido = true; db.Entry(materiaAntiga).State = EntityState.Modified; //db.Materia.Remove(materiaAntiga); } programacao.Apresentadores.Clear(); //programacao.Horario_programacao.Clear(); //programacao.Materia.Clear(); programacao.excluido = true; db.Entry(programacao).State = EntityState.Modified; db.SaveChanges(); GerenciaLogs.saveLog(ref db, WebSecurity.GetUserId(User.Identity.Name), areaADM, TipoAcesso.Exclusao, programacao.id); return(RedirectToAction("Index")); }
public ActionResult Edit(Noticias noticias, HttpPostedFileBase audioUpload, HttpPostedFileBase fotoUpload, string ListaTags = "", string fotoExistente = "", string idEditoria = "") { if (!string.IsNullOrEmpty(fotoExistente)) { noticias.foto = fotoExistente; ModelState.Remove("fotoUpload"); } if (ModelState.IsValid) { #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); } if (!string.IsNullOrEmpty(fotoExistente)) { noticias.foto = fotoExistente; } //noticias.dataAtualizacao = DateTime.Now; db.Entry(noticias).State = EntityState.Modified; db.SaveChanges(); #endregion if (noticias.videoYoutube != null) { if (noticias.videoYoutube.Contains("=")) { string[] keyYoutube = noticias.videoYoutube.Split(new char[] { '=' }); noticias.videoYoutube = keyYoutube[1]; } } #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 (!string.IsNullOrEmpty(idEditoria)) { db.Entry(noticias).Collection("Editoriais").Load(); noticias.Editoriais.Clear(); int idEditorial = Convert.ToInt32(idEditoria); var editorial = db.Editoriais.FirstOrDefault(x => x.id == idEditorial); if (editorial != null) { noticias.Editoriais.Add(editorial); // db.SaveChanges(); } } #endregion db.Entry(noticias).State = EntityState.Modified; 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")); } ViewBag.idEditoria = new SelectList(db.Editoriais.Where(x => !x.excluido && !x.especial), "id", "nome"); 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.AutoCompleteTags = db.Tags.Where(a => !a.Excluido).Select(x => x.Titulo).ToArray(); return(View(noticias)); }
public ActionResult Edit(string editorial, Noticias noticias, HttpPostedFileBase audioUpload, HttpPostedFileBase fotoUpload, int[] TagsIds, int CategoriaId = 0) { var editoria = db.Editoriais.FirstOrDefault(a => a.chave == editorial); if (CategoriaId == 0) { ModelState.AddModelError("CategoriaId", "Selecione uma categoria"); } else if (ModelState.IsValid) { #region uploads if (fotoUpload != 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 path205x125 = Server.MapPath(string.Format(pathFoto205x215, noticias.id)); var path150x90 = Server.MapPath(string.Format(pathFoto150x90, noticias.id)); var path93x93 = Server.MapPath(string.Format(pathFoto93x93, noticias.id)); var path500x300 = Server.MapPath(string.Format(pathFoto500x300, noticias.id)); var fileOriginal = Server.MapPath(string.Format(pathOriginal, noticias.id)); //var file2 = new System.Drawing.Bitmap(fileOriginal); noticias.foto = Utils.SaveFileBase(fileOriginal, fotoUpload); Utils.SaveFileBase(path93x93, fotoUpload, noticias.foto); noticias.fotoMini = noticias.foto; //Utils.SaveAndCropImage(fotoUpload, path700x460, 0, 0, 700, 460, true, noticias.foto); //Utils.SaveAndCropImage(fotoUpload, path620x415, 0, 0, 620, 415, true, noticias.foto); //Utils.SaveAndCropImage(fotoUpload, path620x200, 0, 0, 620, 200, true, noticias.foto); //Utils.SaveAndCropImage(fotoUpload, path300x200, 0, 0, 300, 200, true, noticias.foto); //Utils.SaveAndCropImage(fotoUpload, path205x125, 0, 0, 205, 125, true, noticias.foto); //Utils.SaveAndCropImage(fotoUpload, path150x90, 0, 0, 150, 90, true, noticias.foto); Utils.resizeImageAndSave(fileOriginal + noticias.foto, 700, 460, path700x460); Utils.resizeImageAndSave(fileOriginal + noticias.foto, 620, 415, path620x415); Utils.resizeImageAndSave(fileOriginal + noticias.foto, 620, 200, path620x200); Utils.resizeImageAndSave(fileOriginal + noticias.foto, 300, 200, path300x200); Utils.resizeImageAndSave(fileOriginal + noticias.foto, 205, 125, path205x125); Utils.resizeImageAndSave(fileOriginal + noticias.foto, 150, 90, path150x90); Utils.resizeImageAndSave(fileOriginal + noticias.foto, 500, 300, path500x300); 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 && o.id != noticias.id).Count() > 0); if (audioUpload != null) { var path = Server.MapPath("~/conteudo/noticias/" + noticias.id + "/audio/"); noticias.audio = Utils.SaveFileBase(path, audioUpload); } //noticias.dataAtualizacao = DateTime.Now; if (noticias.dataAtualizacao == null) { noticias.dataAtualizacao = DateTime.Now; } db.Entry(noticias).State = EntityState.Modified; db.SaveChanges(); #endregion var categoria = db.Categorias.Find(CategoriaId); db.Entry(noticias).Collection("Categorias").Load(); db.Entry(noticias).Collection("Tags").Load(); noticias.Tags.Clear(); noticias.Categorias.Clear(); if (TagsIds != null) { foreach (int TagId in TagsIds) { Tags NewTags = db.Tags.Find(TagId); noticias.Tags.Add(NewTags); } } noticias.Categorias.Add(categoria); db.Entry(noticias).State = EntityState.Modified; 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", new { editorial = editorial })); } ViewBag.Editorial = db.Editoriais.FirstOrDefault(a => a.chave == 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.MultiSelectTags = new MultiSelectList(db.Tags.Where(a => !a.Excluido), "Id", "Titulo", noticias.Tags.Select(n => n.Id)); ViewBag.CategoriaId = new SelectList(db.Categorias.Where(a => !a.Excluido && a.EditoriaId == editoria.id).ToList(), "Id", "Titulo", noticias.Categorias.FirstOrDefault().Id); ViewBag.Editorial = editoria; ViewBag.EditorialChave = editoria.chave; return(View(noticias)); }
public ActionResult Edit(Colunista colunista, HttpPostedFileBase fotoUpload, HttpPostedFileBase fotoMiniUpload, string oldPassword = "", string username = "", string password = "", int cropX = 0, int cropY = 0, int cropWidth = 190, int cropHeight = 132) { if (ModelState.IsValid) { if (fotoUpload != null) { if (cropWidth > 0) { colunista.foto = Utils.SaveAndCropColunista(fotoUpload, Server.MapPath("~/Conteudo/Colunistas/Foto/"), cropX, cropY, cropWidth, cropHeight); } else { colunista.foto = Utils.SaveAndCropImage(fotoUpload, Server.MapPath("~/Conteudo/Colunistas/Foto/"), 0, 0, 190, 132); } } ; //if (fotoMiniUpload != null) //{ // colunista.fotoMini = Utils.SaveAndCropImage(fotoMiniUpload, Server.MapPath("~/Conteudo/Colunistas/90x90/"), 0, 0, 90, 90); //} if (password != "" && oldPassword != "" && username != "") { var OldUserName = _db.UserProfiles.Where(x => x.ColunistaId == colunista.id).Select(x => x.UserName).First(); bool hasLocalAccount = OAuthWebSecurity.HasLocalAccount(WebSecurity.GetUserId(OldUserName)); ViewBag.HasLocalPassword = hasLocalAccount; ViewBag.ReturnUrl = Url.Action("Manage"); if (hasLocalAccount) { if (ModelState.IsValid) { // ChangePassword will throw an exception rather than return false in certain failure scenarios. bool changePasswordSucceeded; try { changePasswordSucceeded = WebSecurity.ChangePassword(OldUserName, oldPassword, password); } catch (Exception) { changePasswordSucceeded = false; } if (!changePasswordSucceeded) { ModelState.AddModelError("Senha", "Seu password está incorreto ou o novo password é inválido."); return(View(colunista)); } } } } int suffix = 0; do { colunista.chave = colunista.nome.GenerateSlug() + (suffix > 0 ? suffix.ToString() : ""); suffix++; } while (db.Noticias.Where(o => o.url == colunista.chave && o.id != colunista.id).Count() > 0); db.Entry(colunista).State = EntityState.Modified; db.SaveChanges(); GerenciaLogs.saveLog(ref db, WebSecurity.GetUserId(User.Identity.Name), areaADM, TipoAcesso.Edicao, colunista.id); return(RedirectToAction("Index")); } return(View(colunista)); }
public ActionResult Create(Banners banners, HttpPostedFileBase Arquivo, HttpPostedFileBase Arquivo2, int[] Area, int?Tamanhos) { if (Tamanhos == null) { ModelState.AddModelError("Tamanho", "Escolha um tamanho."); } if (ModelState.IsValid) { Banners banner = new Banners { Anunciante = banners.Anunciante, Arquivo = Arquivo?.FileName, Arquivo2 = Arquivo2?.FileName, DataCadastro = DateTime.Now, DataFim = banners.DataFim, DataInicio = banners.DataInicio, Excluido = false, Exibicoes = 0, Cliques = 0, Link = banners.Link, TipoArquivo = banners.TipoArquivo, Titulo = banners.Anunciante, Local = Tamanhos, Liberado = banners.Liberado, Html = banners.Html }; #region add area if (Tamanhos.HasValue) { AreaBanner Areas = db.AreaBanner.Where(x => x.Id == Tamanhos).FirstOrDefault(); banner.AreaBanner.Add(Areas); } #endregion if (banner.Html != string.Empty) { banner.Arquivo = SalvarArquivo(Arquivo, Tamanhos, 0); banner.Arquivo2 = SalvarArquivo(Arquivo2, Tamanhos, 1); } db.Banners.Add(banner); db.SaveChanges(); GerenciaLogs.saveLog(ref db, WebSecurity.GetUserId(User.Identity.Name), areaADM, TipoAcesso.Insercao, banner.Id); return(RedirectToAction("Index")); } List <AreaBanner> areas = db.AreaBanner.Where(x => x.Ativo.Value).OrderBy(x => x.Titulo).ToList(); List <object> listaArea = new List <object>(); listaArea.Add(new { Text = "Selecione...", Value = "" }); foreach (var a in areas) { listaArea.Add(new { Text = a.Tamanho + " - " + a.Titulo + " - " + a.Descricao, Value = a.Id }); } List <SelectListItem> lista = new List <SelectListItem>(); lista.Add(new SelectListItem { Selected = true, Text = "Selecione...", Value = "" }); ViewBag.Tamanhos = new SelectList(listaArea, "Value", "Text"); return(View(banners)); }
public ActionResult Edit(Programacao programacao, HttpPostedFileBase imagemUpload, HttpPostedFileBase logoUpload, int[] Apresent, int[] Participantes, string horariosTotal, string[] diadaSemana) { var dayList = from DayOfWeek t in Enum.GetValues(typeof(DayOfWeek)) select new { ID = (int)t, Name = Utils.WeekDayName(t) }; ViewBag.diaSemana = new SelectList(dayList, "ID", "Name", programacao.diaSemana); if (ModelState.IsValid) { db.Entry(programacao).State = EntityState.Modified; db.Entry(programacao).Collection("Apresentadores").Load(); programacao.Apresentadores.Clear(); if (Apresent != null) { foreach (int id in Apresent) { var dbApresent = db.Apresentadores.Find(id); programacao.Apresentadores.Add(dbApresent); } } if (Participantes != null) { foreach (int id in Participantes) { var dbApresent = db.Apresentadores.Find(id); programacao.Apresentadores.Add(dbApresent); } } int suffix = 0; do { programacao.chave = programacao.nome.GenerateSlug() + (suffix > 0 ? (suffix++).ToString() : ""); suffix++; } while (db.Programacao.Where(o => o.chave == programacao.chave && o.id != programacao.id).Count() > 0); db.Entry(programacao).Property("dataCadastro").IsModified = false; #region tratamento de horarios List <Horario_programacao> horasAntigas = db.Horario_programacao.Where(x => x.idPrograma == programacao.id).ToList(); foreach (var horaAntiga in horasAntigas) { db.Horario_programacao.Remove(horaAntiga); } if (programacao.periodo == 2) // horario e dia indeterminado { Horario_programacao horario = new Horario_programacao { diaSemana = null, horario = null, idPrograma = programacao.id, Programacao = programacao }; db.Horario_programacao.Add(horario); db.SaveChanges(); } else { string[] result; string[] stringSeparators = new string[] { "/" }; string[] stringSeparators2 = new string[] { "," }; result = horariosTotal.Split(stringSeparators, StringSplitOptions.None); //array de horarios pra cada dia string[] segunda; string[] terca; string[] quarta; string[] quinta; string[] sexta; string[] sabado; string[] domingo; //alimentos com os horarios segunda = result[0].Split(stringSeparators2, StringSplitOptions.None); terca = result[1].Split(stringSeparators2, StringSplitOptions.None); quarta = result[2].Split(stringSeparators2, StringSplitOptions.None); quinta = result[3].Split(stringSeparators2, StringSplitOptions.None); sexta = result[4].Split(stringSeparators2, StringSplitOptions.None); sabado = result[5].Split(stringSeparators2, StringSplitOptions.None); domingo = result[6].Split(stringSeparators2, StringSplitOptions.None); if (segunda[0] != "" || diadaSemana.Contains("box-segunda")) { foreach (var hr in segunda) { Horario_programacao horario = new Horario_programacao { diaSemana = 1, horario = (string.IsNullOrEmpty(hr) ? null : hr), idPrograma = programacao.id, Programacao = programacao }; db.Horario_programacao.Add(horario); } } if (terca[0] != "" || diadaSemana.Contains("box-terca")) { foreach (var hr in terca) { Horario_programacao horario = new Horario_programacao { diaSemana = 2, horario = (string.IsNullOrEmpty(hr) ? null : hr), idPrograma = programacao.id, Programacao = programacao }; db.Horario_programacao.Add(horario); } } if (quarta[0] != "" || diadaSemana.Contains("box-quarta")) { foreach (var hr in quarta) { Horario_programacao horario = new Horario_programacao { diaSemana = 3, horario = (string.IsNullOrEmpty(hr) ? null : hr), idPrograma = programacao.id, Programacao = programacao }; db.Horario_programacao.Add(horario); } } if (quinta[0] != "" || diadaSemana.Contains("box-quinta")) { foreach (var hr in quinta) { Horario_programacao horario = new Horario_programacao { diaSemana = 4, horario = (string.IsNullOrEmpty(hr) ? null : hr), idPrograma = programacao.id, Programacao = programacao }; db.Horario_programacao.Add(horario); } } if (sexta[0] != "" || diadaSemana.Contains("box-sexta")) { foreach (var hr in sexta) { Horario_programacao horario = new Horario_programacao { diaSemana = 5, horario = (string.IsNullOrEmpty(hr) ? null : hr), idPrograma = programacao.id, Programacao = programacao }; db.Horario_programacao.Add(horario); } } if (sabado[0] != "" || diadaSemana.Contains("box-sabado")) { foreach (var hr in sabado) { Horario_programacao horario = new Horario_programacao { diaSemana = 6, horario = (string.IsNullOrEmpty(hr) ? null : hr), idPrograma = programacao.id, Programacao = programacao }; db.Horario_programacao.Add(horario); } } if (domingo[0] != "" || diadaSemana.Contains("box-domingo")) { foreach (var hr in domingo) { Horario_programacao horario = new Horario_programacao { diaSemana = 0, horario = (string.IsNullOrEmpty(hr) ? null : hr), idPrograma = programacao.id, Programacao = programacao }; db.Horario_programacao.Add(horario); } } db.SaveChanges(); } #endregion GerenciaLogs.saveLog(ref db, WebSecurity.GetUserId(User.Identity.Name), areaADM, TipoAcesso.Edicao, programacao.id); return(RedirectToAction("Index")); } ViewBag.EditoriaIdProg = db.Editoriais.Where(ed => ed.chave == "programacao").Select(ed => ed.id).FirstOrDefault(); return(View(programacao)); }
public ActionResult Create(Programacao programacao, HttpPostedFileBase imagem, HttpPostedFileBase logo, int[] ApresentadoresId, int[] ParticipantesId, string horariosTotal, string[] diadaSemana) { var dayList = from DayOfWeek t in Enum.GetValues(typeof(DayOfWeek)) select new { ID = (int)t, Name = Utils.WeekDayName(t) }; if (ModelState.IsValid) { if (ApresentadoresId != null) { foreach (var apresentador in ApresentadoresId) { var apresentadores = db.Apresentadores.Find(apresentador); programacao.Apresentadores.Add(apresentadores); } } if (ParticipantesId != null) { foreach (var participante in ParticipantesId) { var participantes = db.Apresentadores.Find(participante); programacao.Apresentadores.Add(participantes); } } programacao.dataCadastro = DateTime.Now; db.Programacao.Add(programacao); /* * if (imagem != null) * { * var pathCapa = Server.MapPath(caminhoCapa); * var pathLogo = Server.MapPath(caminhoLogo); * // programacao.logo = Utils.SaveAndCropImage(logo, pathLogo, 0, 0, 122, 104); * programacao.imagem = Utils.SaveAndCropImage(imagem, pathCapa, 0, 0, 680, 180); * * } * else * { * ModelState.AddModelError("imagem", "É necessário uma capa."); * // ModelState.AddModelError("logo", "É necessário uma logo para o programa."); * return View(programacao); * } */ int suffix = 0; do { programacao.chave = programacao.nome.GenerateSlug() + (suffix > 0 ? (suffix++).ToString() : ""); suffix++; } while (db.Programacao.Where(o => o.chave == programacao.chave).Count() > 0); db.SaveChanges(); #region tratamento de horarios if (programacao.periodo == 2) // horario e dia indeterminado { Horario_programacao horario = new Horario_programacao { diaSemana = null, horario = null, idPrograma = programacao.id, Programacao = programacao }; db.Horario_programacao.Add(horario); db.SaveChanges(); } else { //========================================== TRATAMENTO DE HORARIOS ========================================== string[] result; string[] stringSeparators = new string[] { "/" }; string[] stringSeparators2 = new string[] { "," }; result = horariosTotal.Split(stringSeparators, StringSplitOptions.None); //array de horarios pra cada dia string[] segunda; string[] terca; string[] quarta; string[] quinta; string[] sexta; string[] sabado; string[] domingo; if (diadaSemana == null) { diadaSemana[0] = string.Empty; } //alimentos com os horarios segunda = result[0].Split(stringSeparators2, StringSplitOptions.None); terca = result[1].Split(stringSeparators2, StringSplitOptions.None); quarta = result[2].Split(stringSeparators2, StringSplitOptions.None); quinta = result[3].Split(stringSeparators2, StringSplitOptions.None); sexta = result[4].Split(stringSeparators2, StringSplitOptions.None); sabado = result[5].Split(stringSeparators2, StringSplitOptions.None); domingo = result[6].Split(stringSeparators2, StringSplitOptions.None); if (!string.IsNullOrEmpty(segunda[0]) || diadaSemana.Contains("box-segunda")) { foreach (var hr in segunda) { Horario_programacao horario = new Horario_programacao { diaSemana = 1, horario = (string.IsNullOrEmpty(hr) ? null : hr), idPrograma = programacao.id, Programacao = programacao }; db.Horario_programacao.Add(horario); } } if (!string.IsNullOrEmpty(terca[0]) || diadaSemana.Contains("box-terca")) { foreach (var hr in terca) { Horario_programacao horario = new Horario_programacao { diaSemana = 2, horario = (string.IsNullOrEmpty(hr) ? null : hr), idPrograma = programacao.id, Programacao = programacao }; db.Horario_programacao.Add(horario); } } if (!string.IsNullOrEmpty(quarta[0]) || diadaSemana.Contains("box-quarta")) { foreach (var hr in quarta) { Horario_programacao horario = new Horario_programacao { diaSemana = 3, horario = (string.IsNullOrEmpty(hr) ? null : hr), idPrograma = programacao.id, Programacao = programacao }; db.Horario_programacao.Add(horario); } } if (!string.IsNullOrEmpty(quinta[0]) || diadaSemana.Contains("box-quinta")) { foreach (var hr in quinta) { Horario_programacao horario = new Horario_programacao { diaSemana = 4, horario = (string.IsNullOrEmpty(hr) ? null : hr), idPrograma = programacao.id, Programacao = programacao }; db.Horario_programacao.Add(horario); } } if (!string.IsNullOrEmpty(sexta[0]) || diadaSemana.Contains("box-sexta")) { foreach (var hr in sexta) { Horario_programacao horario = new Horario_programacao { diaSemana = 5, horario = (string.IsNullOrEmpty(hr) ? null : hr), idPrograma = programacao.id, Programacao = programacao }; db.Horario_programacao.Add(horario); } } if (!string.IsNullOrEmpty(sabado[0]) || diadaSemana.Contains("box-sabado")) { foreach (var hr in sabado) { Horario_programacao horario = new Horario_programacao { diaSemana = 6, horario = (string.IsNullOrEmpty(hr) ? null : hr), idPrograma = programacao.id, Programacao = programacao }; db.Horario_programacao.Add(horario); } } if (!string.IsNullOrEmpty(domingo[0]) || diadaSemana.Contains("box-domingo")) { foreach (var hr in domingo) { Horario_programacao horario = new Horario_programacao { diaSemana = 0, horario = (string.IsNullOrEmpty(hr) ? null : hr), idPrograma = programacao.id, Programacao = programacao }; db.Horario_programacao.Add(horario); } } db.SaveChanges(); } #endregion GerenciaLogs.saveLog(ref db, WebSecurity.GetUserId(User.Identity.Name), areaADM, TipoAcesso.Insercao, programacao.id); return(RedirectToAction("Index")); } ViewBag.ApresentadoresId = new MultiSelectList(db.Apresentadores.Where(a => !a.excluido && a.participanteConvidado == false), "id", "nome"); ViewBag.ParticipantesId = new MultiSelectList(db.Apresentadores.Where(a => !a.excluido && a.participanteConvidado == true), "id", "nome"); ViewBag.diaSemana = new SelectList(dayList, "ID", "Name"); ViewBag.EditoriaIdProg = db.Editoriais.Where(ed => ed.chave == "programacao").Select(ed => ed.id).FirstOrDefault(); //var editoriais = db.Editoriais.Where(a => !a.excluido).ToList(); //int firstId = editoriais.FirstOrDefault().id; //ViewBag.EditoriaId = new SelectList(editoriais, "id", "nome", firstId); return(View(programacao)); }
public ActionResult Edit(Noticias noticias, HttpPostedFileBase fotoUpload, string fotoExistente = "", string idEditoria = "") { if (!string.IsNullOrEmpty(fotoExistente)) { noticias.foto = fotoExistente; ModelState.Remove("fotoUpload"); } if (noticias.texto != null) { if (noticias.texto.Length > 500) { ModelState.Remove("texto"); ModelState.AddModelError("texto", "O Texto não pode conter mais do que 500 caracteres."); } } if (ModelState.IsValid) { noticias.dataCadastro = DateTime.Now; noticias.dataAtualizacao = DateTime.Now; noticias.transito = false; db.Noticias.Add(noticias); db.Entry(noticias).State = EntityState.Modified; if (db.SaveChanges() > 0) { 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 = noticias.titulo.GenerateSlug() + (suffix > 0 ? suffix.ToString() : ""); suffix++; } while (db.Noticias.Where(o => o.url == noticias.url).Count() > 0); #region Editoriais if (!string.IsNullOrEmpty(idEditoria)) { db.Entry(noticias).Collection("Editoriais").Load(); noticias.Editoriais.Clear(); int idEditorial = Convert.ToInt32(idEditoria); var editorial = db.Editoriais.FirstOrDefault(x => x.id == idEditorial); if (editorial != null) { noticias.Editoriais.Add(editorial); } } #endregion db.SaveChanges(); } GerenciaLogs.saveLog(ref db, WebSecurity.GetUserId(User.Identity.Name), areaADM, TipoAcesso.Edicao, noticias.id); return(RedirectToAction("Index", new { EspecialId = 5 })); } return(View(noticias)); }
public ActionResult Edit(Horoscopoes horoscopo, HttpPostedFileBase AudioF, HttpPostedFileBase MiniaturaF) { if (ModelState.IsValid) { horoscopo.DataAtualizacao = DateTime.Now; db.Entry(horoscopo).State = EntityState.Modified; //db.SaveChanges(); if (AudioF != null && AudioF.ContentLength > 0) { var extension = Path.GetExtension(AudioF.FileName); string[] permitidos = { ".mp3", ".mp3 ", ".aac" }; if (!permitidos.Contains(extension.ToLower())) { ModelState.AddModelError("", "Extensão não permitida!"); } else { string AudioAtual = horoscopo.Audio; string caminho = Server.MapPath("~/conteudo/horoscopo/" + horoscopo.Id + "/"); if (System.IO.File.Exists(caminho + AudioAtual)) { System.IO.File.Delete(caminho + AudioAtual); } if (!Directory.Exists(caminho)) { Directory.CreateDirectory(caminho); } AudioF.SaveAs(caminho + AudioF.FileName); horoscopo.Audio = AudioF.FileName; } } //if (MiniaturaF != null && MiniaturaF.ContentLength > 0) //{ // var extension = Path.GetExtension(MiniaturaF.FileName); // string[] permitidos = { ".jpg", ".jpeg", ".gif", ".png" }; // if (!permitidos.Contains(extension.ToLower())) // { // ModelState.AddModelError("", "Extensão não permitida!"); // } // else // { // var Temp = Server.MapPath("~/conteudo/Temp/"); // var pathArquivoFinal = Server.MapPath("~/conteudo/MidiaKit/miniaturas/"); // MiniaturaF.SaveAs(System.IO.Path.Combine(Temp, MiniaturaF.FileName)); // midiakit.Miniatura = Utils.resizeImageAndSave(System.IO.Path.Combine(Temp, MiniaturaF.FileName), 300, 300, pathArquivoFinal); // } //} db.SaveChanges(); GerenciaLogs.saveLog(ref db, WebSecurity.GetUserId(User.Identity.Name), areaADM, TipoAcesso.Edicao, horoscopo.Id); return(RedirectToAction("Index")); } return(View(horoscopo)); }
public ActionResult Edit(Noticias noticias, HttpPostedFileBase fotoUpload, HttpPostedFileBase audioUpload, string fotoExistente = "", string EditorialId = "", int CategoriaId = 0) { if (ModelState.IsValid) { noticias.dataCadastro = DateTime.Now; if (noticias.dataAtualizacao == DateTime.MinValue || noticias.dataAtualizacao == null) { noticias.dataAtualizacao = DateTime.Now; } noticias.transito = false; db.Noticias.Add(noticias); db.Entry(noticias).State = EntityState.Modified; if (db.SaveChanges() > 0) { 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 = noticias.titulo.GenerateSlug() + (suffix > 0 ? suffix.ToString() : ""); suffix++; } while (db.Noticias.Where(o => o.url == noticias.url).Count() > 0); if (!string.IsNullOrEmpty(fotoExistente)) { noticias.foto = fotoExistente; } if (audioUpload != null) { var path = Server.MapPath("~/conteudo/noticias/" + noticias.id + "/audio/"); noticias.audio = Utils.SaveFileBase(path, audioUpload); } #region categorias if (CategoriaId > 0) { db.Entry(noticias).Collection("Categorias").Load(); noticias.Categorias.Clear(); int idCategoria = Convert.ToInt32(CategoriaId); var editorial = db.Categorias.FirstOrDefault(x => x.Id == idCategoria); if (editorial != null) { noticias.Categorias.Add(editorial); } } #endregion #region Editoriais if (!string.IsNullOrEmpty(EditorialId)) { db.Entry(noticias).Collection("Editoriais").Load(); noticias.Editoriais.Clear(); int idEditorial = Convert.ToInt32(EditorialId); var editorial = db.Editoriais.FirstOrDefault(x => x.id == idEditorial); if (editorial != null) { noticias.Editoriais.Add(editorial); } } #endregion db.SaveChanges(); } GerenciaLogs.saveLog(ref db, WebSecurity.GetUserId(User.Identity.Name), getAreaADM(Convert.ToInt32(EditorialId)), TipoAcesso.Edicao, noticias.id); return(RedirectToAction("Index", new { EspecialId = EditorialId })); } return(View(noticias)); }
public ActionResult Create(Noticias noticias, HttpPostedFileBase foto, HttpPostedFileBase audio, string fotoExistente = "", string EditorialId = "", int CategoriaId = 0) { ModelState["dataAtualizacao"]?.Errors.Clear(); if (ModelState.IsValid) { var categoria = db.Categorias.FirstOrDefault(a => a.Id == CategoriaId); noticias.Categorias.Add(categoria); noticias.dataCadastro = DateTime.Now; if (noticias.dataAtualizacao != DateTime.MinValue || noticias.dataAtualizacao != null) { noticias.dataAtualizacao = DateTime.Now; } noticias.transito = false; db.Noticias.Add(noticias); if (db.SaveChanges() > 0) { if (foto != 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, foto); 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 = noticias.titulo.GenerateSlug() + (suffix > 0 ? suffix.ToString() : ""); suffix++; } while (db.Noticias.Where(o => o.url == noticias.url).Count() > 0); if (!string.IsNullOrEmpty(fotoExistente)) { noticias.foto = fotoExistente; } if (audio != null) { var path = Server.MapPath("~/conteudo/noticias/" + noticias.id + "/audio/"); noticias.audio = Utils.SaveFileBase(path, audio); } if (!string.IsNullOrEmpty(EditorialId)) { int idEditorial = Convert.ToInt32(EditorialId); var editorial = db.Editoriais.FirstOrDefault(x => x.id == idEditorial); if (editorial != null) { noticias.Editoriais.Add(editorial); db.SaveChanges(); } } db.Entry(noticias).State = EntityState.Modified; db.SaveChanges(); } GerenciaLogs.saveLog(ref db, WebSecurity.GetUserId(User.Identity.Name), getAreaADM(Convert.ToInt32(EditorialId)), TipoAcesso.Insercao, noticias.id); return(RedirectToAction("Index", new { EspecialId = EditorialId })); } int id = Convert.ToInt32(EditorialId); var editorial1 = db.Editoriais.FirstOrDefault(x => x.id == id); ViewBag.EspecialNome = editorial1.nome; ViewBag.EditorialId = EditorialId; ViewBag.TemSecao = editorial1.Especiais_Modelos.TemSecao; ViewBag.CategoriaId = new SelectList(db.Categorias.Where(a => !a.Excluido && a.EditoriaId == id).ToList(), "Id", "Titulo"); return(View(noticias)); }
public ActionResult Edit(Noticias noticias, HttpPostedFileBase audioUpload, HttpPostedFileBase fotoUpload, int[] CategoriaId, int[] EditoriaId, string ListaTags = "", string fotoExistente = "", string audioExistente = "") { EditoriaId = EditoriaId.Where(id => id > 0).ToArray(); CategoriaId = CategoriaId.Where(id => id > 0).ToArray(); if (!string.IsNullOrEmpty(fotoExistente)) { noticias.foto = fotoExistente; ModelState.Remove("fotoUpload"); } if (!string.IsNullOrEmpty(audioExistente)) { noticias.audio = audioExistente; ModelState.Remove("audio"); } var padrao = @"<(img|a)[^>]*>(?<content>[^<]*)<"; var regex = new Regex(padrao); if (noticias.fotoCredito != null && regex.IsMatch(noticias.fotoCredito)) { ModelState.AddModelError("fotoCredito", "O campo não pode conter código HTML."); } if (noticias.chamada != null && regex.IsMatch(noticias.chamada)) { ModelState.AddModelError("chamada", "O campo não pode conter código HTML."); } 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."); } if (audioUpload != null && !audioUpload.IsExtension("mp3", "aac")) { ModelState.AddModelError("audio", "A extensão do áudio deve ser apenas nos formatos: .mp3 e .aac ."); } if (CategoriaId == null || CategoriaId.Length == 0) { ModelState.AddModelError("CategoriaId", "Selecione uma categoria"); } if (EditoriaId == null || EditoriaId.Length == 0) { ModelState.AddModelError("EditoriaId", "Selecione uma editoria"); } if (ModelState.IsValid) { if (noticias.TipoDestaque.Value == (int)TipoDestaque.Editoria) { noticias.destaqueEditoria = true; noticias.TipoDestaque = null; } 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 path1361x750 = Server.MapPath(string.Format(pathFoto1361x750, noticias.id)); 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); if (noticias.destaqueEditoria) { Utils.resizeImageAndSave3(Path.Combine(fileOriginal, noticias.foto), 1361, 750, path1361x750); } } 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() : string.Empty); 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 categorias db.Entry(noticias).Collection("Categorias").Load(); noticias.Categorias.Clear(); if (CategoriaId.Length > 0) { foreach (var item in CategoriaId) { int idCategoria = Convert.ToInt32(item); var categoria = db.Categorias.FirstOrDefault(x => x.Id == item); if (categoria != null) { noticias.Categorias.Add(categoria); db.SaveChanges(); } } } #endregion #region Editoriais db.Entry(noticias).Collection("Editoriais").Load(); noticias.Editoriais.Clear(); if (EditoriaId.Length > 0) { 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); 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 db.Entry(noticias).State = EntityState.Modified; 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); if (noticias.Editoriais.FirstOrDefault().especial) { return(RedirectToAction("Index", "EditorialNoticias", new { editorial = noticias.Editoriais.FirstOrDefault().chave })); } return(RedirectToAction("Index")); } if (!string.IsNullOrEmpty(noticias.videoYoutube)) { noticias.videoYoutube = "https://www.youtube.com/watch?v=" + noticias.videoYoutube; } noticias.Editoriais.Clear(); 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(); int catId = noticias.Categorias.Count > 0 ? noticias.Categorias.First().Id : db.Categorias.FirstOrDefault(x => !x.Excluido).Id; var editoriais = db.Editoriais.Where(a => !a.excluido && !a.esportes).ToList(); var edtrl = editoriais.FirstOrDefault(a => !a.excluido && a.Categorias.Any(x => x.Id == catId)); int firstId = edtrl == null?editoriais.First().id : edtrl.id; ViewBag.EditoriaId = editoriais; ViewBag.CategoriaId = new SelectList(db.Categorias.Where(a => !a.Excluido && a.EditoriaId == firstId).ToList(), "Id", "Titulo", catId); ViewBag.AutoCompleteTags = db.Tags.Where(a => !a.Excluido).Select(x => x.Titulo).ToArray(); ViewBag.tagsNoticia = ListaTags; 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)); }