public async Task <IActionResult> Create(HojaRutaDTO item) { if (ModelState.IsValid) { ApplicationUser currentUser = await GetCurrentUser(); string cite = await GetCite(item.UnidadEjecutoraId); HojaRuta hojaRuta = item.prepare(currentUser.AspNetUserId, DB); hojaRuta.CiteUE = $"{cite}-CORR.".Replace("NN-", ""); DB.Add(hojaRuta); await DB.SaveChangesAsync(); var parent = hojaRuta.Derivaciones.First(d => d.Padre == -1); if (parent != null) { foreach (var child in hojaRuta.Derivaciones.Where(d => d.Padre == 0)) { child.Padre = parent.Id; } parent.Padre = 0; DB.SaveChanges(); } SetFlashSuccess("La Hoja de Ruta fue creada correctamente"); return(RedirectToAction(nameof(Index), new{ type = Constantes.HRTipoDespachados })); } return(View("_Create", item)); }
public async Task <IActionResult> Edit(int id, [Bind("IdHojaRuta,IdUnidadEjecutora,SolicitudCodigo,IdUnidadNivel3,CiteTramite,CiteFecha,NroFojas,IdEstadoRegistro,IdUsuario,FechaRegistro,HoraRegistro")] HojaRuta hojaRuta) { if (id != hojaRuta.IdHojaRuta) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(hojaRuta); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!HojaRutaExists(hojaRuta.IdHojaRuta)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(hojaRuta)); }
public async Task <IActionResult> Create([Bind("IdHojaRuta,IdUnidadEjecutora,SolicitudCodigo,IdUnidadNivel3,CiteTramite,CiteFecha,NroFojas,IdEstadoRegistro,IdUsuario,FechaRegistro,HoraRegistro")] HojaRuta hojaRuta) { if (ModelState.IsValid) { hojaRuta.FechaRegistro = DateTime.Now; hojaRuta.IdEstadoRegistro = '1'; _context.Add(hojaRuta); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(hojaRuta)); }
public HojaRuta populateDetalle(HojaRuta hr, int idUsuario, ApplicationDbContext DB) { ICollection <HojaRutaDetalle> detalle = new List <HojaRutaDetalle>(); if (hr.Id > 0) { detalle = hr.Derivaciones; } else { var parentHRDetalle = buildParent(hr, idUsuario); detalle.Add(parentHRDetalle); } foreach (var i in Instrucciones) { InstruccionDTO ins = JsonConvert.DeserializeObject <InstruccionDTO>(i); ICollection <HRDetalleInstrucciones> listDetIns = new List <HRDetalleInstrucciones>(); HojaRutaDetalle d = new HojaRutaDetalle(); d.AreaDestinoId = ins.areaId; d.AreaOrigenId = UnidadEjecutoraId; d.FunDstId = ins.funId; d.FunOrgId = OrigenId; d.PlazoDias = 1; d.Proveido = (ins.comentarios != null) ? ins.comentarios : "-"; d.IdEstadoRegistro = Constantes.Registrado; d.IdUsuario = idUsuario; d.FechaRegistro = DateTime.Now; d.DocumentoId = DocumentoId; d.Padre = Parent; foreach (var id in ins.instrucciones) { Instrucciones instruccion = DB.CorrespondenciaInstrucciones.Find(id); if (instruccion != null) { HRDetalleInstrucciones DetIns = new HRDetalleInstrucciones(); DetIns.HRDetalle = d; DetIns.Instruccion = instruccion; listDetIns.Add(DetIns); } } d.HRDetalleInstrucciones = listDetIns; detalle.Add(d); } hr.Derivaciones = detalle; return(hr); }
public HojaRutaDetalle buildParent(HojaRuta hr, int idUsuario) { HojaRutaDetalle parent = new HojaRutaDetalle(); parent.AreaDestinoId = hr.UnidadEjecutoraId; parent.AreaOrigenId = hr.UnidadEjecutoraId; parent.FunDstId = hr.OrigenId; parent.FunOrgId = hr.OrigenId; parent.PlazoDias = 1; parent.Proveido = "-"; parent.IdEstadoRegistro = Constantes.Registrado; parent.IdUsuario = idUsuario; parent.FechaRegistro = DateTime.Now; parent.DocumentoId = DocumentoId; parent.Padre = -1; return(parent); }
public HojaRuta prepare(int idUsuario, ApplicationDbContext DB) { HojaRuta hojaRuta = new HojaRuta(); hojaRuta.UnidadEjecutoraId = UnidadEjecutoraId; hojaRuta.OrigenId = OrigenId; hojaRuta.Referencia = Referencia; hojaRuta.CiteTramite = CiteDoc; hojaRuta.CiteFecha = FechaDoc; hojaRuta.NroFojas = NroFojas; hojaRuta.CiteHojaRuta = $"MUMANAL/CORR.{TipoHojaRuta} "; hojaRuta.TipoHojaRuta = TipoHojaRuta; hojaRuta.IdEstadoRegistro = Constantes.Enviado; hojaRuta.IdUsuario = idUsuario; hojaRuta.FechaRegistro = DateTime.Now; hojaRuta.Prioridad = Prioridad; hojaRuta.DocumentoId = DocumentoId; hojaRuta.RemitenteExterno = Remitente; hojaRuta.EntidadExterna = UnidadEjecutoraNombre; hojaRuta = populateDetalle(hojaRuta, idUsuario, DB); hojaRuta = populateAnexos(hojaRuta, idUsuario, DB); return(hojaRuta); }
public HojaRuta populateAnexos(HojaRuta hr, int idUsuario, ApplicationDbContext DB) { ICollection <Anexo> anexosArray = new List <Anexo>(); if (hr.Id > 0 && hr.Anexos != null) { anexosArray = hr.Anexos; } foreach (var a in Anexos) { if (a != null) { AnexoDTO anexo = JsonConvert.DeserializeObject <AnexoDTO>(a); Anexo an = new Anexo(); if (anexo.id != null) { an.Id = Int32.Parse(anexo.id); } an.HRDetalleId = 0; an.TipoId = anexo.tipoId; an.Descripcion = anexo.descripcion; an.PathArchivo = anexo.path; an.NombreArchivo = anexo.name; an.Size = anexo.size; an.IdEstadoRegistro = Constantes.Registrado; an.IdUsuario = idUsuario; an.FechaRegistro = DateTime.Now; anexosArray.Add(an); } } hr.Anexos = anexosArray; return(hr); }
public static IHojaRuta GetHojaRuta() { HojaRuta hojaRuta = new HojaRuta(); return((IHojaRuta)hojaRuta); }