public ActionResult Create(Secoes_Locais local, HttpPostedFileBase Imagem, string fotoExistente = "") { if (ModelState.IsValid) { local.DataCadastro = DateTime.Now; local.Excluido = false; db.Secoes_Locais.Add(local); var editoriaId = db.Editoriais.FirstOrDefault(x => x.Especiais_Secoes.Any(w => w.Id == local.SecaoId)).id; if (db.SaveChanges() > 0) { if (Imagem != null) { var path405x270 = Server.MapPath(string.Format(pathFoto405x270, local.Id)); var path365x240 = Server.MapPath(string.Format(pathFoto365x240, local.Id)); var path260x173 = Server.MapPath(string.Format(pathFoto260x173, local.Id)); var fileOriginal = Server.MapPath(string.Format(pathOriginal, local.Id)); local.Imagem = Utils.SaveFileBase(fileOriginal, Imagem); Utils.resizeImageAndSave3(Path.Combine(fileOriginal, local.Imagem), 405, 270, path405x270); Utils.resizeImageAndSave3(Path.Combine(fileOriginal, local.Imagem), 365, 240, path365x240); Utils.resizeImageAndSave3(Path.Combine(fileOriginal, local.Imagem), 260, 173, path260x173); } int suffix = 0; do { local.Chave = local.Titulo.GenerateSlug() + (suffix > 0 ? suffix.ToString() : ""); suffix++; } while (db.Secoes_Locais.Where(o => o.Chave == local.Chave).Count() > 0); if (!string.IsNullOrEmpty(fotoExistente)) { local.Imagem = fotoExistente; } db.Entry(local).State = EntityState.Modified; db.SaveChanges(); } GerenciaLogs.saveLog(ref db, WebSecurity.GetUserId(User.Identity.Name), areaADM, TipoAcesso.Insercao, local.Id); return(RedirectToAction("Index", new { EspecialId = editoriaId })); } var especialId = db.Editoriais.FirstOrDefault(x => x.Especiais_Secoes.Any(w => w.Id == local.SecaoId)).id; ViewBag.SecaoId = new SelectList(db.Especiais_Secoes.Where(x => x.EditoriaId == especialId && !x.Excluido), "Id", "Titulo", local.SecaoId); return(View(local)); }
// // GET: /Locais/Delete/5 public ActionResult Delete(int id = 0) { Secoes_Locais secoes_locais = db.Secoes_Locais.Find(id); if (secoes_locais == null) { return(HttpNotFound()); } return(View(secoes_locais)); }
public ActionResult DeleteConfirmed(int id) { Secoes_Locais secoes_locais = db.Secoes_Locais.Find(id); //db.Secoes_Locais.Remove(secoes_locais); secoes_locais.Excluido = true; db.Entry(secoes_locais).State = EntityState.Modified; db.SaveChanges(); GerenciaLogs.saveLog(ref db, WebSecurity.GetUserId(User.Identity.Name), areaADM, TipoAcesso.Exclusao, secoes_locais.Id); return(RedirectToAction("Index")); }
// // GET: /Locais/Edit/5 public ActionResult Edit(int id = 0) { Secoes_Locais secoes_locais = db.Secoes_Locais.Find(id); if (secoes_locais == null) { return(HttpNotFound()); } ViewBag.EspecialNome = secoes_locais.Especiais_Secoes.Editoriais.nome; ViewBag.EspecialId = secoes_locais.Especiais_Secoes.EditoriaId; ViewBag.SecaoId = new SelectList(db.Especiais_Secoes.Where(x => x.EditoriaId == secoes_locais.Especiais_Secoes.EditoriaId), "Id", "Titulo", secoes_locais.SecaoId); return(View(secoes_locais)); }