public string Update(tb_anexo anexo) { string retorno = ""; var existingAnx = db.tb_anexo.Where(s => s.codAnexo == anexo.codAnexo).FirstOrDefault <tb_anexo>(); if (existingAnx != null) { existingAnx.codOcorrencia = anexo.codOcorrencia; existingAnx.codTipoAnexo = anexo.codTipoAnexo; existingAnx.anexo = anexo.anexo; existingAnx.tipoAnexo = anexo.tipoAnexo; existingAnx.data = anexo.data; existingAnx.hora = anexo.hora; db.SaveChanges(); retorno = "Anexo alterado com sucesso"; } else { retorno = "Anexo não encontrado"; } return(retorno); }
public tb_anexo Add(tb_anexo anexo) { tb_anexo anx = db.tb_anexo.Add(anexo); db.SaveChanges(); return(anx); }
public tb_anexo Remove(long id) { tb_anexo anx = db.tb_anexo.Find(id); db.tb_anexo.Remove(anx); db.SaveChanges(); return(anx); }
public HttpResponseMessage ListarAnexoId(long codAnexo) { tb_anexo result = anexoService.Get(codAnexo); if (result == null) { return(Request.CreateResponse(HttpStatusCode.BadRequest, "Anexo não encontrado")); } return(Request.CreateResponse(HttpStatusCode.OK, result)); }
public HttpResponseMessage DeletarAnexo(long codAnexo) { tb_anexo result = anexoService.Get(codAnexo); if (result == null) { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Anexo não encontrado")); } else { anexoService.Remove(result.codAnexo); var resp = new HttpResponseMessage() { Content = new StringContent("{\"Message\":\"Anexo deletado com sucesso\"}") }; resp.Content.Headers.ContentType = new MediaTypeHeaderValue("application/json"); return(resp); } }
public tb_anexo Get(long id) { tb_anexo anx = db.tb_anexo.Find(id); return(anx); }
public string UploadFile() { var message = HttpContext.Current.Request.Files.AllKeys.Any().ToString(); //try //{ if (HttpContext.Current.Request.Files.AllKeys.Any()) { // Get the uploaded image from the Files collection var httpPostedFile = HttpContext.Current.Request.Files["UploadedImage"]; if (httpPostedFile != null) { var autonumeroCliente = Convert.ToInt32(HttpContext.Current.Request.Form["autonumeroCliente"].ToString()); var siglaCliente = HttpContext.Current.Request.Form["siglaCliente"].ToString().Trim(); var descricao = HttpContext.Current.Request.Form["descricao"].ToString().Trim(); var caminho = "~/UploadedFiles/" + siglaCliente + "/"; // Criar a pasta se não existir ou devolver informação sobre a pasta var inf = Directory.CreateDirectory(HttpContext.Current.Server.MapPath(caminho)); var extension = Path.GetExtension(httpPostedFile.FileName); var fileName = Path.GetFileNameWithoutExtension(Path.GetRandomFileName()) + extension; var fileSavePath = Path.Combine(HttpContext.Current.Server.MapPath(caminho), fileName); if (File.Exists(fileSavePath)) { File.Delete(fileSavePath); } // Save the uploaded file to "UploadedFiles" folder httpPostedFile.SaveAs(fileSavePath); using (var dc = new manutEntities()) { var k = new tb_anexo { siglaCliente = siglaCliente, autonumeroCliente = autonumeroCliente, url = fileName, descricao = descricao }; dc.tb_anexo.Add(k); dc.SaveChanges(); var auto = Convert.ToInt32(k.autonumero); return(auto.ToString("#######0")); } } } return(message); //} //catch (DbEntityValidationException e) //{ // var sb = new StringBuilder(); // foreach (var eve in e.EntityValidationErrors) // { // sb.AppendLine(string.Format("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:", // eve.Entry.Entity.GetType().Name, // eve.Entry.State)); // foreach (var ve in eve.ValidationErrors) // { // sb.AppendLine(string.Format("- Property: \"{0}\", Error: \"{1}\"", // ve.PropertyName, // ve.ErrorMessage)); // } // } // message = sb.ToString(); // //throw new DbEntityValidationException(sb.ToString(), e); //} //catch (Exception ex) //{ // message = ex.InnerException != null // ? ex.InnerException.ToString().Substring(0, 130) + " - SaveFiles" // : ex.Message + " - DataprodutoController SaveFilesFoto"; //} //return message; }