public ActionResult SalvarArquivo(IEnumerable <HttpPostedFileBase> files, TicketAnexoEntity entity) { TicketModel model2 = new TicketModel(); TicketAnexoModel model = new TicketAnexoModel(); model.TicketAnexoEntity = entity; if (files != null) { foreach (var file in files) { string fileName = ""; string path = Server.MapPath("~/Arquivos/Ticket/Anexo/"); if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } // Verify that the user selected a file if (file != null && file.ContentLength > 0) { // extract only the fielname fileName = Path.GetFileNameWithoutExtension(file.FileName) + "-" + entity.TicketId + Path.GetExtension(file.FileName); path = Path.Combine(path, fileName); if (System.IO.File.Exists(path)) { path = GetFileName(path); fileName = Path.GetFileName(path); } file.SaveAs(path); if (ModelState.IsValid) { var entity2 = new TicketAnexoEntity(); entity2.TicketId = entity.TicketId; entity2.Observacao = entity.Observacao; entity2.CaminhoArquivo = "~/Arquivos/Ticket/Anexo/" + fileName; // entity2.TpArq = Path.GetExtension(fileName); new TicketAnexoBusiness().Salvar(entity2, this.UsuarioId); } } } } model.TicketAnexoEntity = new TicketAnexoEntity() { TicketId = entity.TicketId }; //context.TicketAnexoEntity.Where(a => a.TicketId == entity.TicketId) model.TicketAnexoList = TicketBusiness.PesquisarAnexoPorTicket(entity.TicketId).ToList(); return(PartialView("_TicketAnexo", model)); }
public ActionResult InserirTicketAnexo(TicketAnexoEntity model) { if (ModelState.IsValid) { try { new TicketAnexoBusiness().Salvar(model, this.UsuarioId); } catch (TicketException ex) { ModelState.AddModelError("ex", ex.Message); } } return(View("PrincipalTicket", model.TicketId)); }
public ActionResult Upload(TicketAnexoEntity model) { if (Request.Files.Count > 0) { var file = Request.Files[0]; string fileName = ""; string path = Server.MapPath("~/Arquivos/Ticket/Anexo/"); if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } if (file != null && file.ContentLength > 0) { fileName = Path.GetFileNameWithoutExtension(file.FileName) + "-" + model.TicketId + Path.GetExtension(file.FileName); path = Path.Combine(path, fileName); if (System.IO.File.Exists(path)) { path = GetFileName(path); } file.SaveAs(path); } if (ModelState.IsValid) { try { model.CaminhoArquivo = String.Format("~/Arquivos/Ticket/Anexo/{0}", fileName); model.Visibilidade = 1; new TicketAnexoBusiness().Salvar(model, this.UsuarioId); return(RedirectToAction("Ticket/Index")); } catch (TicketException ex) { ModelState.AddModelError("ex", ex.Message); } } } return(View("~/Views/Ticket/_Ticket.cshtml", model.TicketId)); // return RedirectToAction("TicketAnexo"); }
public void Salvar(TicketAnexoEntity entity, int ticketAnexoId) { try { using (SynsTicketContext context = new SynsTicketContext()) { base.SaveChanges(entity, ticketAnexoId, true, context); } } catch (TicketException ex) { this.Erros.Add(ex); } finally { if (this.Erros.Count > 0) { throw new TicketException(this.ConsisteErros()); } } }