public TbSeAdjunto Adjunto(AdjuntoViewModel domain) { TbSeAdjunto aj = new TbSeAdjunto { IdMensaje = domain.IdMensaje, Ruta = domain.Ruta, Estado = domain.Estado }; return(aj); }
public ActionResult CrearComentarioPost(MensajeViewModel model) { var id = User.Claims.FirstOrDefault(x => x.Type == ClaimTypes.NameIdentifier)?.Value; TbSeAdjunto AdjuntoDomain = new TbSeAdjunto(); List <TbSeAdjunto> listaAdjuntos = new List <TbSeAdjunto>(); try { var comentario = this.IMensajeMap.Crear(model, int.Parse(id)); comentario = this.ImensajeService.create(comentario); if (model.Files != null) { var savePath = System.IO.Path.Combine(hostingEnvironment.WebRootPath, "Files"); var rutas = FotosService.SubirAdjuntos(model.Files, savePath); foreach (var item in rutas) { AdjuntoDomain = this.IAdjuntoMap.crear(comentario.Id, item); listaAdjuntos.Add(AdjuntoDomain); } } else { AdjuntoDomain = this.IAdjuntoMap.crear(comentario.Id, ""); listaAdjuntos.Add(AdjuntoDomain); } this.IAdjuntoService.Crear(listaAdjuntos); return(Json(new { success = true })); } catch (Exception ex) { AltivaLog.Log.Insertar(ex.ToString(), "Error"); throw; } }
public ActionResult CrearComentarioPost(MensajeViewModel model) { var id = User.Claims.FirstOrDefault(x => x.Type == ClaimTypes.NameIdentifier)?.Value; TbSeAdjunto AdjuntoDomain = new TbSeAdjunto(); List <TbSeAdjunto> listaAdjuntos = new List <TbSeAdjunto>(); try { var comentario = this.IMensajeMap.Crear(model, int.Parse(id)); comentario = this.ImensajeService.create(comentario); if (model.Files != null) { var rutas = FotosService.SubirAdjuntos(model.Files); foreach (var item in rutas) { AdjuntoDomain = this.IAdjuntoMap.crear(comentario.Id, item); } listaAdjuntos.Add(AdjuntoDomain); } else { AdjuntoDomain = this.IAdjuntoMap.crear(comentario.Id, ""); listaAdjuntos.Add(AdjuntoDomain); } this.IAdjuntoService.Crear(listaAdjuntos); return(Json(new { success = true })); } catch (Exception) { return(BadRequest()); //throw; } }
public ActionResult Crear(MensajeViewModel collection) { try { if (!ModelState.IsValid) { return(RedirectToAction(nameof(Index))); } var ids = User.Claims.FirstOrDefault(x => x.Type == ClaimTypes.NameIdentifier)?.Value; var id = User.Claims.FirstOrDefault(x => x.Type == ClaimTypes.NameIdentifier)?.Value; MensajeViewModel adjunto = new MensajeViewModel(); TbSeMensaje msj = new TbSeMensaje(); TbSeMensajeReceptor msjReceptor = new TbSeMensajeReceptor(); TbSeAdjunto AdjuntoDomain = new TbSeAdjunto(); List <TbSeAdjunto> s = new List <TbSeAdjunto>(); List <TbSeMensajeReceptor> MensajeReceptor = new List <TbSeMensajeReceptor>(); msj = this.IMensajeMap.Crear(collection, int.Parse(id)); msj = this.ImensajeService.create(msj); List <string> correos = new List <string>(); TbSeUsuario userEmail = new TbSeUsuario(); if (collection.Files != null) { foreach (var item in collection.Files) { var savePath = System.IO.Path.Combine(hostingEnvironment.WebRootPath, "Files"); // var path = $"wwwroot\\Files\\{item.FileName}"; var path = $"{savePath}\\{item.FileName}"; using (var stream = new FileStream(path, FileMode.Create)) { item.CopyTo(stream); } var ruta = $"/Files/{item.FileName}"; AdjuntoDomain = this.IAdjuntoMap.crear(msj.Id, ruta); s.Add(AdjuntoDomain); } } else { AdjuntoDomain = this.IAdjuntoMap.crear(msj.Id, ""); s.Add(AdjuntoDomain); } this.IAdjuntoService.Crear(s); foreach (var item in collection.Usuarios) { int i = int.Parse(item); userEmail = this.IUserService.GetSingleUser(i); correos.Add(userEmail.Correo); msjReceptor = this.IMensajeReceptorMap.Crear(msj.Id, i); MensajeReceptor.Add(msjReceptor); } this.IMensajeReceptorService.Crear(MensajeReceptor); // insertarNotificacion(collection, int.Parse(id), correos); this.IBitacoraMap.CrearBitacora(Convert.ToInt32(ids), "Creo un nuevo Mensaje", msj.Id, "Mensaje"); return(RedirectToAction(nameof(Index))); } catch (InvalidCastException e) { // Extract some information from this exception, and then // throw it to the parent method. AltivaLog.Log.Insertar(e.ToString(), "Error"); if (e.Source != null) { Console.WriteLine("IOException source: {0}", e.Source); } throw; } }