private bool Guardar(ActaSeguimGestionVentasModel actaVentas, ref string mensaje) { bool guardado = false; guardado = gestionVentasController.InsertOrUpdateGestionVentas(actaVentas, ref mensaje); return(guardado); }
public bool InsertOrUpdateGestionVentas(ActaSeguimGestionVentasModel ventas, ref string mensaje) { bool insertado = false; using (FonadeDBLightDataContext db = new FonadeDBLightDataContext(_cadena)) { decimal ValorAnt = (from g in db.ActaSeguimGestionVentas where g.codConvocatoria == ventas.codConvocatoria && g.codProyecto == ventas.codProyecto && g.numActa == (ventas.numActa - 1) select g.valor).FirstOrDefault(); if (ventas.valor >= ValorAnt) { var actaVentas = (from g in db.ActaSeguimGestionVentas where g.codConvocatoria == ventas.codConvocatoria && g.codProyecto == ventas.codProyecto && g.numActa == ventas.numActa select g).FirstOrDefault(); if (actaVentas != null)//Actualizar { actaVentas.descripcion = ventas.descripcion; actaVentas.valor = ventas.valor; actaVentas.fechaIngreso = DateTime.Now; } else//Insertar { ActaSeguimGestionVentas gesVentas = new ActaSeguimGestionVentas { descripcion = ventas.descripcion, codConvocatoria = ventas.codConvocatoria, codProyecto = ventas.codProyecto, numActa = ventas.numActa, visita = ventas.visita, fechaIngreso = DateTime.Now, valor = ventas.valor }; db.ActaSeguimGestionVentas.InsertOnSubmit(gesVentas); } db.SubmitChanges(); insertado = true; } else { mensaje = "La cantidad ingresada de valor en ventas acumulada no puede ser menor al de la última visita."; } } return(insertado); }
protected void btnGuardar_Click(object sender, EventArgs e) { ActaSeguimGestionVentasModel actaSegVentas = new ActaSeguimGestionVentasModel(); //actaSegVentas.valor = Convert.ToDecimal(txtCantidad.Text); decimal number; if (Decimal.TryParse(txtCantidad.Text, out number)) { actaSegVentas.valor = number; } actaSegVentas.descripcion = txtDescripcionEvento.Text; actaSegVentas.codConvocatoria = CodigoConvocatoria; actaSegVentas.codProyecto = CodigoProyecto; actaSegVentas.numActa = NumeroActa; actaSegVentas.visita = NumeroActa; if (number >= 0) { string mensaje = ""; if (Guardar(actaSegVentas, ref mensaje)) { Alert("Se registraron los datos correctamente"); cargarGridIndicador(CodigoProyecto, CodigoConvocatoria); LimpiarCampos(); } else if (mensaje != "") { Alert(mensaje); } else { Alert("No logró guardar la informacion"); } } else { Alert("El valor a ingresar debe ser mayor o igual que 0"); } }