/// <summary> /// Funcion encargada de guardar un nuevo registro en la base de datos /// </summary> /// <param name="nDetallePeriodo"></param> public static void Guardar(DetallePeriodo nDetallePeriodo) { try { using (var ctx = new DataModel()) { ctx.Entry(nDetallePeriodo).State = System.Data.Entity.EntityState.Added; ctx.SaveChanges(); } } catch (Exception) { throw; } }
protected void btGuardar_Click(object sender, EventArgs e) { var transaction = SessionHelper.Current.BeginTransaction(); var faltan = false; foreach (C1GridViewRow row in gridResumen.Rows) { // Si el item esta tildado pongo el estado del parte es Verificado var chkVerificar = row.FindControl("chkVerificar") as CheckBox; if (chkVerificar != null && chkVerificar.Checked) { var id = Convert.ToInt32(gridResumen.DataKeys[row.RowIndex].Value); var doc = DAOFactory.DocumentoDAO.FindById(id); ParteSaveStrategy.SetValor(doc, ParteCampos.EstadoControl, 1, PartePersonal.Verificado.ToString()); DAOFactory.DocumentoDAO.SaveOrUpdate(doc); } else { faltan = true; } } // Si todos los partes de este periodo estan verificados... if (!faltan) { // Obtengo el DetallePeriodo para el Transportista o lo creo si no existe var periodo = DAOFactory.PeriodoDAO.FindById(IdPeriodo); var detalle = (from DetallePeriodo det in periodo.Detalles where det.Transportista.Id == IdTransportista select det).ToList(); DetallePeriodo detPeriodo; if (detalle.Count == 0) { detPeriodo = new DetallePeriodo { Periodo = periodo, Transportista = DAOFactory.TransportistaDAO.FindById(IdTransportista) }; periodo.Detalles.Add(detPeriodo); } else { detPeriodo = detalle[0]; } // Seteo el estado del DetallePeriodo a Liquidado detPeriodo.Estado = Periodo.Liquidado; // Busco los partes que no esten verificados (excepto los de este Transportista) var controlados = DAOFactory.DocumentoDAO.FindPartesControlados(IdTransportista, periodo.FechaDesde, periodo.FechaHasta); var partes = from Documento doc in controlados where Convert.ToInt32(doc.Valores[ParteCampos.Empresa]) != IdTransportista select doc; if (!partes.Any()) { // Si no quedaron partes sin verificar cierro el periodo completo periodo.Estado = Periodo.Liquidado; } DAOFactory.PeriodoDAO.SaveOrUpdate(periodo); } transaction.Commit(); BindPeriodos(); gridResumen.DataSource = null; gridResumen.DataBind(); btGuardar.Visible = false; panelResultado.Visible = false; }