public async Task Update(BecarioInterno BI)// UpdateSolicitud { try { var result = await _ctx.BecarioInterno.FirstOrDefaultAsync(e => e.BecarioInternoId == BI.BecarioInternoId); if (result != null) { if (await ValidarDuplicados(BI)) { throw new ApplicationException("Ya existe un registro con ese nombre. Intente cambiar el tipo de beca o las fecha de inicio o término"); } if (BI.Adjunto != null) { Adjunto key = await new AdjuntoRepository().CreateAd(BI.Adjunto); BI.AdjuntoId = key.AdjuntoId; } _ctx.Entry(result).CurrentValues.SetValues(BI); await _ctx.SaveChangesAsync(); PersonasRepository prep = new PersonasRepository(); Personas p = await prep.GetByClave(BI.ClavePersona); p.ultimaActualizacion = DateTime.Now; await prep.Update(p); } } catch (Exception e) { throw new Exception(e.Message, e); } }
private async Task insertaAdjunto(Aliado model, int convenioId) { try { for (int i = 0; i < model.AdjuntosNombreConvenio.Length; i++) { Adjunto obj = new Adjunto(); var item2 = model.AdjuntosRutaConvenio[i]; var item = model.AdjuntosNombreConvenio[i]; obj.RutaCompleta = item2; obj.nombre = item; obj.ModuloId = "CR"; var entities = _dbGEN.dbSetAdjuntos.Add(obj); await _dbGEN.SaveChangesAsync(); var adjuntoId = entities.AdjuntoId; await insertaAdjuntoConvenio(model, adjuntoId, convenioId); } } catch (Exception e) { throw new Exception(e.Message, e); } }
public async Task Update(HistorialPI historial) { try { if (historial.Adjunto != null) { if (historial.Adjunto.AdjuntoId == 0) { Adjunto key = await new AdjuntoRepository().CreateAd(historial.Adjunto); historial.AdjuntoId = key.AdjuntoId; historial.Adjunto.AdjuntoId = key.AdjuntoId; } } var _historial = await _pictx.Historial.FirstOrDefaultAsync(e => e.HistorialPIId == historial.HistorialPIId); if (_historial != null) { _pictx.Entry(_historial).CurrentValues.SetValues(historial); await _pictx.SaveChangesAsync(); } } catch (Exception e) { throw new Exception(e.Message, e); } }
public async Task Update(TemasInnovacion model) { try { var _model = await _db.DbSetTemasInnovacion.FirstOrDefaultAsync(e => e.TemaId == model.TemaId); if (_model != null) { //Cuando se elimina el adjunto en modo edicion if (model.AdjuntoId != null) { int id = Convert.ToInt32(model.AdjuntoId); model.AdjuntoId = null; _db.Entry(_model).CurrentValues.SetValues(model); await _db.SaveChangesAsync(); await _adjuntoRepo.Delete(id); } //Cuando se agrega un nuevo archivo if (model.Adjunto != null && model.AdjuntoId == null) { Adjunto key = await _adjuntoRepo.CreateAd(model.Adjunto); model.AdjuntoId = key.AdjuntoId; model.Adjunto.AdjuntoId = key.AdjuntoId; } if (model.claveAutores != null) { var autoresRegistro = await _db.DbSetAutores.Where(e => e.idOC == 6 && e.ContenidoId == model.TemaId).AsNoTracking().ToListAsync(); //Eliminacion de autores AutoresCPRepository autoresRepo = new AutoresCPRepository(); foreach (var c in autoresRegistro) { await autoresRepo.Delete(c.AutorId); } Autores autor = new Autores(); foreach (var clave in model.claveAutores) { autor.clave = clave; autor.ContenidoId = model.TemaId; autor.idOC = 6; autor.FechaRegistro = DateTime.Now; _db.DbSetAutores.Add(autor); await _db.SaveChangesAsync(); } } _db.Entry(_model).CurrentValues.SetValues(model); await _db.SaveChangesAsync(); await cambiaEstadoPublicacion(_model); } } catch (Exception e) { throw new Exception(e.Message, e); } }
public async Task <Adjunto> UpdateAdjunto(Adjunto adjunto) { //return await _unitOfWork.UpdateAdjunto(producto); _unitOfWork.AdjuntoRepository.Update(adjunto); await _unitOfWork.SaveChangesAsync(); return(adjunto); }
public async Task <IHttpActionResult> Update(BecarioDirigido Obj) { try { log.Info(new MDCSet(this.ControllerContext.RouteData)); if (Obj.Adjunto != null) { //Elimar archivo if (Obj.Adjunto.nombre == "eliminar") { int id = Convert.ToInt32(Obj.AdjuntoId); Obj.AdjuntoId = null; await _repository.Update(Obj); await _adjuntoRepo.Delete(id); return(Ok()); } ///Agregar archivo al editar if (Obj.Adjunto.AdjuntoId == 0) { Adjunto key = await _adjuntoRepo.CreateAd(Obj.Adjunto); Obj.AdjuntoId = key.AdjuntoId; Obj.Adjunto.AdjuntoId = key.AdjuntoId; await _repository.Update(Obj); return(Ok(key)); } } //solución de ALAN replicada if (Obj.Adjunto != null) { Obj.AdjuntoId = Obj.Adjunto.AdjuntoId; } await _repository.Update(Obj); ////Agregar a OC if (Obj.EstadoFlujoId == 3) { await new NuevoOCRepository().Create( new NuevoOC("CH", "BecarioDirigido", Obj.NombreEstancia, "IndexCH.html#/detallesbecariodirigido/" + Obj.BecarioDirigidoId + "/", Obj.BecarioDirigidoId + "" )); } return(Ok(Obj)); } catch (Exception e) { log.Error(new MDCSet(this.ControllerContext.RouteData), e); return(InternalServerError(e)); } }
public bool Guardar() { Adjunto adj = new Adjunto(); SolicitudAdjuntos solAdj = new SolicitudAdjuntos(); if (sol == null) { sol = Solicitud.GetById(BiFactory.Sol.Id_Solicitud); } solAdj.IdSolicitud = sol.Id_Solicitud; long lMaxFileSize = 3000000; string sFileDir = Server.MapPath("~/upload/"); if ((Request.Files[0] != null) && (Request.Files[0].ContentLength > 0)) { //determine file name string OriginalName = System.IO.Path.GetFileName(Request.Files[0].FileName); string sFileName = string.Empty; try { if (Request.Files[0].ContentLength <= lMaxFileSize) { //Save File on disk sFileName = System.Guid.NewGuid().ToString(); Request.Files[0].SaveAs(sFileDir + sFileName); //relacionar el adjunto adj.PathFile = sFileDir + sFileName; adj.Date = System.DateTime.Now; adj.FileName = OriginalName; adj.Size = Request.Files[0].ContentLength; adj.ContentType = Request.Files[0].ContentType; adj.Save(); solAdj.IdAdjunto = adj.IdAdjunto; solAdj.Save(); lblMessage.Visible = true; lblMessage.Text = "Se agrego el archivo correctamente."; } else //reject file { lblMessage.Visible = true; lblMessage.Text = "El tamaño del archivo supera el limite de " + lMaxFileSize; } } catch (Exception ee)//in case of an error { lblMessage.Visible = true; lblMessage.Text = ee.Message; } } FillAdjuntos(); return true; }
/******************************************METHOD'S*******************************/ public async Task <Adjunto> deleteById(int Id) { Adjunto adjunto = findById(Id).Result; adjunto.Dml = "D"; dbContext.Adjuntos.Update(adjunto); await dbContext.SaveChangesAsync(); return(adjunto); }
public async Task <Adjunto> findById(int Id) { if (Id == null || Id == 0) { return(new Adjunto()); } Adjunto adjunto = await dbContext.Adjuntos.FindAsync(Id); return(adjunto); }
public async Task <Adjunto> save(Adjunto adjunto) { adjunto.Dml = "I"; adjunto.UpDateTime = new DateTime(); adjunto.CreateTime = new DateTime(); dbContext.Adjuntos.Add(adjunto); await dbContext.SaveChangesAsync(); return(adjunto); }
public void insert_return_ID1() { Adjunto newobj = new Adjunto { Archivo = "new test", Ruta = "new test" }; DB_Entity.Adjunto.Add(newobj); DB_Entity.SaveChanges(); int Ret_ID = newobj.ID; }
/// <summary> /// Envio de email con un adjunto. /// </summary> /// <param name="to"></param> /// <param name="subject"></param> /// <param name="body"></param> /// <param name="isHtmlBody"></param> /// <param name="attachment"></param> /// <param name="resultMessage"></param> /// <returns></returns> public static bool SendMailWithAttachment(string to, string subject, string body, bool isHtmlBody, Adjunto attachment, out string resultMessage) { return(SendMailWithAttachment(to, subject, body, isHtmlBody, new List <Adjunto> { attachment }, out resultMessage)); }
public async Task Update(Ponencia Obj)// UpdateSolicitud { try { var result = await _ctx.Ponencia.FirstOrDefaultAsync(e => e.PonenciaId == Obj.PonenciaId); if (Obj.EstadoFlujoId == 1 && result.EstadoFlujoId == 3) { await new NuevoOCRepository().DeleteId("PonenciaCH", result.PonenciaId + ""); } if (result != null) { if (Obj.Adjunto != null) { //Eliminar archivo if (Obj.Adjunto.nombre == "eliminar") { int id = Convert.ToInt32(Obj.Adjunto.AdjuntoId); result.AdjuntoId = null; await _ctx.SaveChangesAsync(); await new AdjuntoRepository().Delete(id); } ///Agregar archivo al editar if (Obj.Adjunto.AdjuntoId == 0) { if (result.AdjuntoId != null) { var id = result.AdjuntoId; result.AdjuntoId = null; await _ctx.SaveChangesAsync(); await new AdjuntoRepository().Delete(id); } Adjunto key = await new AdjuntoRepository().CreateAd(Obj.Adjunto); Obj.AdjuntoId = key.AdjuntoId; } } _ctx.Entry(result).CurrentValues.SetValues(Obj); await _ctx.SaveChangesAsync(); } PersonasRepository prep = new PersonasRepository(); Personas p = await prep.GetByClave(Obj.ClavePersona); p.ultimaActualizacion = DateTime.Now; await prep.Update(p); } catch (Exception e) { throw new Exception(e.Message, e); } }
public async Task <IActionResult> AddFileAsync(FacturaViewModel model) { try { if (ModelState.IsValid) { var files = HttpContext.Request.Form.Files; var path = Path.Combine(_environment.WebRootPath, @"uploads\" + model.InvoiceNumber); if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } if (files.Count > 0) { foreach (var file in files) { if (file.Length > 0) { if (System.IO.File.Exists(path + @"\" + file.FileName)) { var adjunto1 = await _context.Adjuntos.FirstOrDefaultAsync(a => a.DocumentName.Trim() == file.FileName.Trim()); if (adjunto1 != null) { await DeleteFileAsync(adjunto1.Id); } } //var completePath = Path.Combine(@path, file.FileName); using (var fileStream = new FileStream(Path.Combine(path, file.FileName), FileMode.Create)) { await file.CopyToAsync(fileStream); } var adjunto = new Adjunto { RegisterDate = DateTime.Now, User = _userSession.UserName, DocumentUrl = path, DocumentName = file.FileName, Factura = await _context.Facturas.FirstOrDefaultAsync(f => f.Id == model.Id) }; _context.Adjuntos.Add(adjunto); await _context.SaveChangesAsync(); } } } return(new JsonResult(true)); } } catch (Exception) { return(RedirectToAction(nameof(Index))); } return(RedirectToAction($"Edit/{model.Id}")); }
public List<Entidad> getAdjuntos() { List<Entidad> listaA = new List<Entidad>(); foreach (ListItem item in ListBoxArchivos.Items) { Adjunto a = new Adjunto(); a.Titulo = item.Text; listaA.Add(a); } return listaA; }
public async Task Update(Avance model) { try { var _model = await _db.DbSetAvance.FirstOrDefaultAsync(e => e.AvanceId == model.AvanceId); if (_model != null) { if (model.AdjuntoId != null) { int id = Convert.ToInt32(model.AdjuntoId); model.AdjuntoId = null; _db.Entry(_model).CurrentValues.SetValues(model); await _db.SaveChangesAsync(); await _adjuntoRepo.Delete(id); } if (model.Adjunto != null && model.AdjuntoId == null) { Adjunto key = await _adjuntoRepo.CreateAd(model.Adjunto); model.AdjuntoId = key.AdjuntoId; model.Adjunto.AdjuntoId = key.AdjuntoId; } if (model.avances != null) { //Se eliminan los anteriores para crear un nuevo registro de los agregados var Autores = await _db.DbSetAvanceMiembros.Where(e => e.AvanceId == model.AvanceId). Select(x => x.AvanceMiembroId).ToListAsync(); AvanceMiembrosRepository av = new AvanceMiembrosRepository(); foreach (var aut in Autores) { await av.Delete(aut); } //Ahora se crean los nuevos autores foreach (var c in model.avances) { c.AvanceId = model.AvanceId; c.FechaRegistro = DateTime.Now;; await av.Create(c); } } _db.Entry(_model).CurrentValues.SetValues(model); await _db.SaveChangesAsync(); } } catch (Exception e) { throw new Exception(e.Message, e); } }
public async Task Create(Adjunto model) { try { _db.dbSetAdjuntos.Add(model); await _db.SaveChangesAsync(); } catch (Exception e) { throw new Exception(e.Message, e); } }
public List <Entidad> getAdjuntos() { List <Entidad> listaA = new List <Entidad>(); foreach (ListItem item in ListBoxArchivos.Items) { Adjunto a = new Adjunto(); a.Titulo = item.Text; listaA.Add(a); } return(listaA); }
public async Task <bool> UpdateAdjunto(Adjunto adjunto) { var currentAdjunto = await GetAdjunto(adjunto.Id); currentAdjunto.Nombrearchivo = adjunto.Nombrearchivo; currentAdjunto.Ubicacion = adjunto.Ubicacion; currentAdjunto.IdRef = adjunto.IdRef; currentAdjunto.Tipo = adjunto.Tipo; int rows = await _context.SaveChangesAsync(); return(rows > 0); }
/// <summary> /// Actualiza un registro de la tabla asociaciones /// </summary> /// <param name="asociaciones">objeto de tipo asociaciones que contiene los datos para actualizar </param> /// <returns></returns> public async Task Update(Asociaciones asociaciones) { try { var _asociaciones = await _ctx.Asociaciones.FirstOrDefaultAsync(e => e.AsociacionesId == asociaciones.AsociacionesId); if (_asociaciones != null) { if (asociaciones.Adjunto != null) { AdjuntoRepository _adjuntoRepo = new AdjuntoRepository(); //Eliminar archivo if (asociaciones.Adjunto.nombre == "eliminar") { var id = asociaciones.Adjunto.AdjuntoId; _asociaciones.AdjuntoId = null; asociaciones.AdjuntoId = null; await _ctx.SaveChangesAsync(); await _adjuntoRepo.Delete(id); //formacionacademica.Adjunto = null; //await _faRepo.Update(formacionacademica); } ///Agregar archivo al editar if (asociaciones.Adjunto.AdjuntoId == 0) { if (_asociaciones.AdjuntoId != null) { var id = _asociaciones.AdjuntoId; _asociaciones.AdjuntoId = null; await _ctx.SaveChangesAsync(); await _adjuntoRepo.Delete(id); } Adjunto key = await _adjuntoRepo.CreateAd(asociaciones.Adjunto); asociaciones.AdjuntoId = key.AdjuntoId; } } _ctx.Entry(_asociaciones).CurrentValues.SetValues(asociaciones); await _ctx.SaveChangesAsync(); } } catch (Exception e) { throw new Exception(e.Message, e); } }
public async Task <IHttpActionResult> GetDatos(long id) { try{ log.Info(new MDCSet(this.ControllerContext.RouteData), new InfoException(id)); Adjunto fil = await adjuntoRepo.GetAsync(id); var mime = UtilMime.GetMimeMapping(fil.nombre); var obj = new { nombre = fil.nombre, mime = mime }; return(Ok(obj)); } catch (Exception e) { log.Error(new MDCSet(this.ControllerContext.RouteData), e); return(InternalServerError(e)); } }
private async Task <long> CreateAdjuntoSwMT(Adjunto model) { try { model.ModuloId = "MT"; _db.dbSetAdjuntoOfMT.Add(model); await _db.SaveChangesAsync(); return(model.AdjuntoId); } catch (Exception e) { throw new Exception(e.Message, e); } }
public ActionResult jstest4(int id) { //token tk = new token(); //tk.master(); List <Adjunto> lst = tc2.ts(); Adjunto lst2 = lst.SingleOrDefault(); TempData.Clear(); TempData["t1"] = lst2; ViewBag.list1 = lst; return(View()); }
public HttpResponseMessage GetFile(long id) //id del Adjunto { var localFilePath = ""; var nombre = "download"; try { log.Info(new MDCSet(this.ControllerContext.RouteData)); Adjunto fil = adjuntoRepo.Get(id); localFilePath = fil.RutaCompleta; nombre = fil.nombre; UtileriasArchivo util = new UtileriasArchivo(); return(util.GetFile(localFilePath, nombre, Request)); } catch (Exception e) { log.Error(new MDCSet(this.ControllerContext.RouteData), e); return(Request.CreateErrorResponse(HttpStatusCode.NotFound, e.Message + " (" + nombre + ")")); } }
public async Task <Comunidad> Update(Comunidad model) { try { var _model = await _db.DbSetComunidades.FirstOrDefaultAsync(e => e.ComunidadId == model.ComunidadId); if (_model != null) { //Cuando se elimina el adjunto en modo edicion if (model.idAjunto != null) { int id = Convert.ToInt32(model.idAjunto); model.idAjunto = null; _db.Entry(_model).CurrentValues.SetValues(model); await _db.SaveChangesAsync(); await _adjuntoRepo.Delete(id); } if (model.Adjunto != null && model.idAjunto == null) { Adjunto key = await _adjuntoRepo.CreateAd(model.Adjunto); model.idAjunto = key.AdjuntoId; model.Adjunto.AdjuntoId = key.AdjuntoId; String file = string.Empty; var archivo = model.Adjunto.RutaCompleta; try { Byte[] bytes = File.ReadAllBytes(archivo); file = Convert.ToBase64String(bytes); model.Adjunto64 = file; } catch (Exception e) { model.Adjunto64 = null; } } _db.Entry(_model).CurrentValues.SetValues(model); await _db.SaveChangesAsync(); } return(model); } catch (Exception e) { throw new Exception(e.Message, e); } }
public async Task Update(Competidor model) { try { var _model = await _dbComp.Competidor.FirstOrDefaultAsync(e => e.CompetidorId == model.CompetidorId); if (_model != null) { _dbComp.Entry(_model).CurrentValues.SetValues(model); await _dbComp.SaveChangesAsync(); //Se eliminan los adjuntos anteriores del registro, esto evita tener multiples listas de adjuntos (nuevos, viejos) por cada adjunto que agregue/elimine el usuario var fksAdjuntos = await _dbComp.AdjuntoPorCompetidor.Where(e => e.CompetidorId == model.CompetidorId).ToListAsync(); if (fksAdjuntos.Count() > 0) { var listaAdjuntos = fksAdjuntos.Select(x => x.AdjuntoId).ToList(); _dbComp.AdjuntoPorCompetidor.RemoveRange(fksAdjuntos); await _dbComp.SaveChangesAsync(); await new AdjuntoRepository().DeleteByCollectionIds(listaAdjuntos); } //Se registran los adjuntos de nuevo if (model.AdjuntoPorCompetidor.Count > 0) { foreach (var item in model.AdjuntoPorCompetidor) { Adjunto obj = new Adjunto(); obj.RutaCompleta = item.Adjunto.RutaCompleta; obj.nombre = item.Adjunto.nombre; obj.ModuloId = "CR"; var entities = _dbGEN.dbSetAdjuntos.Add(obj); await _dbGEN.SaveChangesAsync(); await insertaAdjuntosCompetidor(item.Autor, obj.AdjuntoId, item.tipo, model.CompetidorId);//string autor, long IdAdjunto, string tipo, int idcompetidor } // await insertaAdjunto(model); } } } catch (Exception e) { throw new Exception(e.Message, e); } }
public IActionResult SaveAdjunto(Adjunto adjunto) { Response <Adjunto> response = new Response <Adjunto>(); try { IAdjuntoService service = new AdjuntoService(DbContext); Task <Adjunto> p = service.save(adjunto); response.ok(true, p.Result, "Se inserto el adjunto"); return(Ok(response)); } catch (Exception ex) { response.ok(false, null, "Error en el servicio " + ex.Message); return(BadRequest(response)); } }
/// <summary> /// Actualiza un registro de la tabla de idiomas /// </summary> /// <param name="idioma">objeto de tipo Idiomas con los nuevos datos</param> /// <returns></returns> public async Task Update(Idiomas idioma) { try { var _idioma = await _ctx.Idiomas.FirstOrDefaultAsync(e => e.IdiomasId == idioma.IdiomasId); if (_idioma != null) { if (idioma.Adjunto != null) { //Eliminar archivo if (idioma.Adjunto.nombre == "eliminar") { int id = Convert.ToInt32(idioma.Adjunto.AdjuntoId); _idioma.AdjuntoId = null; idioma.AdjuntoId = null; await _ctx.SaveChangesAsync(); await new AdjuntoRepository().Delete(id); } ///Agregar archivo al editar if (idioma.Adjunto.AdjuntoId == 0) { if (_idioma.AdjuntoId != null) { var id = _idioma.AdjuntoId; _idioma.AdjuntoId = null; await _ctx.SaveChangesAsync(); await new AdjuntoRepository().Delete(id); } Adjunto key = await new AdjuntoRepository().CreateAd(idioma.Adjunto); idioma.AdjuntoId = key.AdjuntoId; } } _ctx.Entry(_idioma).CurrentValues.SetValues(idioma); await _ctx.SaveChangesAsync(); } } catch (Exception e) { throw new Exception(e.Message, e); } }
public IActionResult DeleteAttachedById(int Id) { IAdjuntoService service = new AdjuntoService(DbContext); Response <Adjunto> response = new Response <Adjunto>(); try { Adjunto p = service.deleteById(Id).Result; response.ok(true, p, "Se cambio el estado a DELETE"); return(Ok(response)); } catch (Exception ex) { response.ok(false, new Adjunto(), "Error al cambiar estado " + ex.Message); return(BadRequest(response)); } }
public void jsontest() { Adjunto product = new Adjunto(); //Product product = new Product(); product.ID = 999; product.Archivo = "Archivo"; product.Ruta = "Ruta"; string output = JsonConvert.SerializeObject(product); var a = Encriptar(output); var b = Desencriptar(a); Adjunto deserializedProduct = JsonConvert.DeserializeObject <Adjunto>(output); }
public async Task Update(Adjunto model) { try { var _model = await _db.dbSetAdjuntos.FirstOrDefaultAsync(e => e.AdjuntoId == model.AdjuntoId); if (_model != null) { _db.Entry(_model).CurrentValues.SetValues(model); await _db.SaveChangesAsync(); } } catch (Exception e) { throw new Exception(e.Message, e); } }
public async Task Update(SNI sni) { try { var _sni = await _ctx.SNI.FirstOrDefaultAsync(e => e.SNIId == sni.SNIId); if (_sni != null) { if (sni.Adjunto != null) { //Eliminar archivo if (sni.Adjunto.nombre == "eliminar") { int id = Convert.ToInt32(sni.Adjunto.AdjuntoId); _sni.AdjuntoId = null; await _ctx.SaveChangesAsync(); await new AdjuntoRepository().Delete(id); } ///Agregar archivo al editar if (sni.Adjunto.AdjuntoId == 0) { if (_sni.AdjuntoId != null) { var id = _sni.AdjuntoId; _sni.AdjuntoId = null; await _ctx.SaveChangesAsync(); await new AdjuntoRepository().Delete(id); } Adjunto key = await new AdjuntoRepository().CreateAd(sni.Adjunto); sni.AdjuntoId = key.AdjuntoId; sni.Adjunto.AdjuntoId = key.AdjuntoId; } } _ctx.Entry(_sni).CurrentValues.SetValues(sni); await _ctx.SaveChangesAsync(); } } catch (Exception e) { throw new Exception(e.Message, e); } }
public ActionResult AgregarAdjunto(Adjunto Adjunto) { try { string msg; Adjunto.FechaHora = DateTime.Now; if (ModelState.IsValid) { msg = "Adjunto creado <b>exitósamente</b>"; _AdjuntoService.Create(Adjunto); var Adjuntos = _AdjuntoService.GetAll().ToList(); return Json(new { msg = "Detalle creado <b>exitosamente</b>", status = status_success, contenido = RenderPartialViewToString("_AdjuntoList", Adjuntos) }); } else{ msg = "No se pudo guardar la información exitósamente, intente de nuevo."; return Json(new { msg = msg , status = status_error }); } } catch(Exception e) { return Json(new { status = false, msg = e.Message }); } }
private void GuardarCalidad() { Adjunto adj = new Adjunto(); SolicitudAdjuntos solAdj = new SolicitudAdjuntos(); if (sol == null) { sol = Solicitud.GetById(BiFactory.Sol.Id_Solicitud); } solAdj.IdSolicitud = sol.Id_Solicitud; long lMaxFileSize = 3000000; string sFileDir = Server.MapPath("~/Archivos_Calidad/Uploads/" + DateTime.Now.Year.ToString() + "/"); if (!Directory.Exists(sFileDir)) { Directory.CreateDirectory(sFileDir); } if ((Request.Files[0] != null) && (Request.Files[0].ContentLength > 0)) { //determine file name string OriginalName = System.IO.Path.GetFileName(Request.Files[0].FileName); try { if (!File.Exists(sFileDir + Request.Files[0].FileName)) { if ((Request.Files[0].ContentLength <= lMaxFileSize)) { //Save File on disk //sFileName = System.Guid.NewGuid().ToString(); Request.Files[0].SaveAs(sFileDir + OriginalName); //relacionar el adjunto adj.PathFile = sFileDir + OriginalName; adj.Date = System.DateTime.Now; adj.FileName = OriginalName; adj.Size = Request.Files[0].ContentLength; adj.ContentType = Request.Files[0].ContentType; adj.Calidad = true; adj.Save(); solAdj.IdAdjunto = adj.IdAdjunto; solAdj.Save(); lblMessage.Visible = true; lblMessage.Text = "El Archivo se adjunto Correctamente."; } else //reject file { lblMessage.Visible = true; lblMessage.Text = "El tamaño del archivo supera el limite de " + lMaxFileSize; } } else { lblMessage.Visible = true; lblMessage.Text = "El archivo " + OriginalName + " ya existe "; } } catch (Exception ee)//in case of an error { lblMessage.Visible = true; lblMessage.Text = ee.Message; } } FillAdjuntos(); }
public ActionResult AgregarAdjunto(int PedidoID) { Adjunto Adjunto = new Adjunto(); if (Request.IsAjaxRequest()) { Adjunto.Pedido_ID = PedidoID; Adjunto.Version = 1; return PartialView("_AgregarAdjunto", Adjunto); } return View(Adjunto); }