//obtener por id public ListPaisDto GetById(int id) { var pais = new ListPaisDto(); try { using (var ctx = new PresupuestoContext()) { pais = (from p in ctx.SPPais join m in ctx.SPMoneda on p.monedaId equals m.Id where p.Id == id select new ListPaisDto { Id = p.Id, nombre = p.nombre, monedaId = p.monedaId, moneda = m.nombre, simbolo_moneda = m.simbolo }).SingleOrDefault(); } } catch (Exception e) { throw e; } return(pais); }
public List <ListPaisDto> GetAll() { var list = new List <ListPaisDto>(); try { using (var ctx = new PresupuestoContext()) { list = (from p in ctx.SPPais join m in ctx.SPMoneda on p.monedaId equals m.Id where p.estado == "A" select new ListPaisDto { Id = p.Id, nombre = p.nombre, monedaId = p.monedaId, moneda = m.nombre, simbolo_moneda = m.simbolo }).ToList(); } }catch (Exception e) { throw e; } return(list); }
public List <ListVariedadesDto> GetAll() { var list = new List <ListVariedadesDto>(); try { using (var ctx = new PresupuestoContext()) { list = (from v in ctx.Variedades join g in ctx.Gruposcultivos on v.GrupoCultivo equals g.Codigo select new { codigo = v.Codigo, descripcion = v.Descripcion, grupo = g.Descripcion, codigoGrupo = g.Codigo }).Select(x => new ListVariedadesDto { codigo = x.codigo, descripcion = x.descripcion, grupo = x.grupo, codigoGrupo = x.codigoGrupo }).ToList(); } } catch (Exception) { } return(list); }
public string ActivarODesactivarLote(int loteId, string estado) { var rpta = ""; try { using (var ctx = new PresupuestoContext()) { var lote = ctx.SPSubLote.Where(x => x.Id == loteId).SingleOrDefault(); lote.estado = estado; ctx.Entry(lote).State = EntityState.Modified; ctx.SaveChanges(); if (estado == "A") { rpta = "Lote ah sido activado"; } else { rpta = "Lote ha sido desactivado"; } } } catch { throw; } return(rpta); }
//metodo para guardar actividads public string Save() { string rpta = ""; this.estado = "I"; this.fecha = DateTime.Today; try { using (var ctx = new PresupuestoContext()) { if (this.Id > 0) { ctx.Entry(this).State = EntityState.Modified; } else { ctx.Entry(this).State = EntityState.Added; } ctx.SaveChanges(); rpta = "presupuesto ah sido registrado con exito"; } } catch (Exception e) { throw e; } return(rpta); }
//metodo para guardar actividads public string Save() { string rpta = ""; this.estado = "A"; try { using (var ctx = new PresupuestoContext()) { if (this.Id > 0) { ctx.Entry(this).State = EntityState.Modified; } else { ctx.Entry(this).State = EntityState.Added; } ctx.SaveChanges(); rpta = "Tipo cambio registrada con exito"; } } catch (Exception e) { throw e; } return(rpta); }
//get permisos por usuaios public List <UserInfo> GetPermisos(int usuarioId) { var list = new List <UserInfo>(); try { using (var ctx = new PresupuestoContext()) { list = (from up in ctx.SPUsuarioPermiso join p in ctx.SPPermiso on up.permisoId equals p.Id where up.usuarioId == usuarioId select new { Id = up.Id, usuarioId = up.usuarioId, permisoId = up.permisoId, codigo_permiso = p.codigo }).Select(x => new UserInfo { Id = x.Id, usuarioId = x.usuarioId, permisoId = x.permisoId, codigo_permiso = x.codigo_permiso }).ToList(); } } catch (Exception) { } return(list); }
//get paises por usuaios public List <UserPais> GetPaises(int usuarioId) { var list = new List <UserPais>(); try { using (var ctx = new PresupuestoContext()) { list = (from up in ctx.SPUsuarioPais join p in ctx.SPPais on up.paisId equals p.Id where up.usuarioId == usuarioId select new { Id = up.Id, usuarioId = up.usuarioId, paisId = up.paisId, pais = p.nombre }).Select(x => new UserPais { Id = x.Id, usuarioId = x.usuarioId, paisId = x.paisId, pais = x.pais }).ToList(); } } catch (Exception) { } return(list); }
public List <ListDimensionesDto> GetAll() { var list = new List <ListDimensionesDto>(); try { using (var ctx = new PresupuestoContext()) { //list = ctx.SPDimension.Where(x => x.estado == "A").ToList(); list = (from d in ctx.SPDimension join g in ctx.SPGrupoDimension on d.grupoId equals g.Id where d.estado == "A" select new ListDimensionesDto { Id = d.Id, grupoId = d.grupoId, factor = d.factor, estado = d.estado, nombre = d.nombre, nombre_cuenta = d.cuenta_contable + "-" + d.nombre_cuenta, agrupador = g.nombre, cuenta_contable = d.cuenta_contable }).ToList(); } } catch (Exception e) { throw e; } return(list); }
//metodo para eliminar a nivel logico una actividad public bool Delete(int id) { var rpta = false; try { using (var ctx = new PresupuestoContext()) { var tipo = this.GetById(id); if (tipo != null) { tipo.estado = "I"; ctx.Entry(tipo).State = EntityState.Modified; ctx.SaveChanges(); rpta = true; } } } catch (Exception e) { throw e; } return(rpta); }
//guardar un empleado public string Save() { var rpta = ""; try { using (var ctx = new PresupuestoContext()) { this.estado = "A"; if (this.empleadoId > 0) { ctx.Entry(this).State = EntityState.Modified; } else { ctx.SPEmpleado.Add(this); } ctx.SaveChanges(); } } catch { } return(rpta); }
public List <ListDimensionActividad> GetDimensionesbyActividad(string actividad) { var list = new List <ListDimensionActividad>(); try { using (var ctx = new PresupuestoContext()) { list = (from a in ctx.SPActividad join g in ctx.SPGrupoDimension on a.grupoId equals g.Id join d in ctx.SPDimension on g.Id equals d.grupoId where a.codigo == actividad select new ListDimensionActividad { dimensionId = d.Id, factor = d.factor, grupoId = g.Id }).ToList(); } } catch (Exception e) { throw e; } return(list); }
public List <ListLoteDto> GetByFinca(string fincaId) { var list = new List <ListLoteDto>(); try { using (var ctx = new PresupuestoContext()) { list = (from sl in ctx.SPSubLote join l in ctx.SPLote on sl.loteId equals l.Id join g in ctx.Gruposcultivos on sl.cultivoId equals g.Codigo join v in ctx.Variedades on sl.variedadId equals v.Codigo where l.fincaId == fincaId select new ListLoteDto { Id = sl.Id, nombre = sl.nombre, lote = l.nombre, loteId = l.Id, cultivo = g.Descripcion.Trim() + " " + v.Descripcion.Trim(), }).ToList(); } } catch (Exception e) { throw e; } return(list); }
public List <ListTipoCambioDto> GetAll() { var list = new List <ListTipoCambioDto>(); try { using (var ctx = new PresupuestoContext()) { list = (from t in ctx.SPTipoCambio join p in ctx.SPPais on t.paisId equals p.Id join m in ctx.SPMoneda on p.monedaId equals m.Id select new ListTipoCambioDto { Id = t.Id, paisId = t.paisId, pais = p.nombre, moneda = m.nombre, fecha = t.fecha, tipo_cambio = t.tipo_cambio }).ToList(); } } catch (Exception e) { throw e; } return(list); }
//eliminar detalles de presupuesto public bool Delete(int Id) { var rpta = false; try { using (var ctx = new PresupuestoContext()) { var dPresupuesto = ctx.SPDetallePresupuesto.Where(x => x.Id == Id).SingleOrDefault(); if (dPresupuesto != null) { var dimensiones = ctx.SPCostoByDimension.Where(x => x.detalle_presupuesdoId == Id).ToList(); //eliminamos los existentes en el detalle ctx.SPCostoByDimension.RemoveRange(dimensiones); ctx.SaveChanges(); ctx.Entry(dPresupuesto).State = EntityState.Deleted; ctx.SaveChanges(); rpta = true; } } } catch { } return(rpta); }
//obtener centros de costo asignados mas sus estados public List <ListPresupuestoDto> GetByAsignaciones(int presupuestoId) { var list = new List <ListPresupuestoDto>(); try { using (var ctx = new PresupuestoContext()) { list = (from c in ctx.SPSubCentroCosto from pm in ctx.SPDetallePresupuesto.Where(x => c.Id == x.fincaId).DefaultIfEmpty() where pm.presupuestoId == presupuestoId || pm.presupuestoId.Equals(null) group pm by new { c.nombre, pm.fincaId, pm.estado } into hh select new { centro_costo = hh.Key.nombre, fincaId = hh.Key.fincaId, estado = hh.Key.estado }).Select(x => new ListPresupuestoDto { centro_costo = x.centro_costo, estado = x.estado }).ToList(); } } catch (Exception e) { throw e; } return(list); }
//agrupar detalles por lote public List <ListDetallDto> GetByGroup(int presupuestoId, int fincaId) { var list = new List <ListDetallDto>(); try { using (var ctx = new PresupuestoContext()) { list = (from dm in ctx.SPDetallePresupuesto join l in ctx.SPSubLote on dm.subloteId equals l.Id where dm.presupuestoId == presupuestoId && dm.fincaId == fincaId group dm by new { dm.subloteId, l.nombre, dm.presupuestoId } into hh select new { presupuestoId = hh.Key.presupuestoId, loteId = hh.Key.subloteId, nombre = hh.Key.nombre, suma = hh.Sum(x => x.total_referencia), }).Select(x => new ListDetallDto { loteId = x.loteId, lote = x.nombre, total_lote = x.suma, presupuestoId = x.presupuestoId }).ToList(); } } catch (Exception e) { throw e; } return(list); }
public List <ListTipoPresupuestoDto> GetByUser(int userId) { var list = new List <ListTipoPresupuestoDto>(); try { using (var ctx = new PresupuestoContext()) { list = (from up in ctx.SPUsuarioPresupuesto join p in ctx.SPTipoPresupuesto on up.tipoId equals p.tipoId where up.usuarioId == userId select new ListTipoPresupuestoDto { Id = up.Id, tipoId = up.tipoId, icon = p.icon, nombre = p.nombre, clase = p.clase, url = p.url }).ToList(); } } catch (Exception) { } return(list); }
public ResponseModel Acceder(string user, string contraseña) { var rm = new ResponseModel(); try { using (var ctx = new PresupuestoContext()) { contraseña = HashHelper.SHA256(contraseña); var usuario = ctx.SPUsuario.Where(x => x.email == user || x.usuario == user) .Where(x => x.password == contraseña && x.estado == "A") .SingleOrDefault(); if (usuario != null) { SessionHelper.AddUserToSession(usuario.Id.ToString()); rm.SetResponse(true); } else { rm.SetResponse(false, "Correo o contraseña incorrecta"); } } } catch (Exception) { throw; } return(rm); }
//obtener detalles por presupuest y centro de costo public List <ListDetallDto> GetByCCostoCosecha(int presupuestoId, int fincaId) { var list = new List <ListDetallDto>(); try { using (var ctx = new PresupuestoContext()) { list = (from dm in ctx.SPDetallePresupuesto join l in ctx.SPSubLote on dm.subloteId equals l.Id join g in ctx.Gruposcultivos on l.cultivoId equals g.Codigo join v in ctx.Variedades on l.variedadId equals v.Codigo join u in ctx.SPUnidadMedida on dm.unidad_by_p_cs equals u.unidadId where dm.presupuestoId == presupuestoId && dm.fincaId == fincaId select new { Id = dm.Id, fincaId = dm.fincaId, presupuestoId = dm.presupuestoId, loteId = dm.subloteId, lote = l.nombre, cantidad = dm.cantidad, total_referencia = dm.total_referencia, unidad_media = u.nombre, total = ctx.SPDetallePresupuesto.Where(x => x.presupuestoId == presupuestoId && x.fincaId == fincaId).Sum(x => x.total_referencia), estado = dm.estado, cultivo = g.Descripcion.Trim() + " " + v.Descripcion.Trim(), unidad_by_p_cs = dm.unidad_by_p_cs, costo_by_p_cs = dm.costo_by_p_cs, costo = dm.costo_by_p_cs } ).Select(x => new ListDetallDto { id = x.Id, loteId = x.loteId, lote = x.lote, cantidad = x.cantidad, total_referencia = x.total_referencia, fincaId = x.fincaId, presupuestoId = x.presupuestoId, total = x.total, unidad_medida = x.unidad_media, estado = x.estado, cultivo = x.cultivo, unidad_by_p_cs = x.unidad_by_p_cs, costo_by_p_cs = x.costo_by_p_cs, costo = x.costo }).ToList(); //list = ctx.SPDetallePreManoObra.Where(x => x.presupuestoId == presupuestoId && x.fincaId == fincaId).ToList(); } } catch (Exception e) { throw e; } return(list); }
//obtener detalles por presupuest y centro de costo public List <ListDetallDto> GetByCCosto(int presupuestoId, int fincaId) { var list = new List <ListDetallDto>(); try { using (var ctx = new PresupuestoContext()) { list = (from dm in ctx.SPDetallePresupuesto join l in ctx.SPSubLote on dm.subloteId equals l.Id join a in ctx.SPActividad on dm.referencia equals a.codigo join u in ctx.SPUnidadMedida on a.unidadId equals u.unidadId where dm.presupuestoId == presupuestoId && dm.fincaId == fincaId select new { Id = dm.Id, fincaId = dm.fincaId, presupuestoId = dm.presupuestoId, referencia = dm.referencia, actividad = a.nombre, loteId = dm.subloteId, lote = l.nombre, cantidad = dm.cantidad, costo = a.costo, total_referencia = dm.total_referencia, unidad_media = u.nombre, total = ctx.SPDetallePresupuesto.Where(x => x.presupuestoId == presupuestoId && x.fincaId == fincaId).Sum(x => x.total_referencia), estado = dm.estado, tipo = a.tipo } ).Select(x => new ListDetallDto { id = x.Id, nombre_referencia = x.actividad, referencia = x.referencia, loteId = x.loteId, lote = x.lote, cantidad = x.cantidad, total_referencia = x.total_referencia, costo = x.costo, fincaId = x.fincaId, presupuestoId = x.presupuestoId, total = x.total, unidad_medida = x.unidad_media, estado = x.estado, tipo = x.tipo }).ToList(); //list = ctx.SPDetallePreManoObra.Where(x => x.presupuestoId == presupuestoId && x.fincaId == fincaId).ToList(); } } catch (Exception e) { throw e; } return(list); }
//metodo para listar lotes public List <ListLoteDto> GetAll(int loteId) { var list = new List <ListLoteDto>(); try { using (var ctx = new PresupuestoContext()) { list = (from sl in ctx.SPSubLote join l in ctx.SPLote on sl.loteId equals l.Id where sl.loteId == loteId select new { Id = sl.Id, codigo = sl.codigo, fincaId = l.fincaId, loteId = l.Id, lote = l.nombre, techado = sl.techado, fecha_inicio = sl.fecha_inicio, fecha_fin = sl.fecha_fin, metros = sl.metros, altura = sl.altura, ancho = sl.ancho, factor_manzana = sl.factor_manzana, densidad = sl.densidad, nombre = sl.nombre, descripcion = sl.descripcion, estado = sl.estado, }).Select(x => new ListLoteDto { Id = x.Id, codigo = x.codigo, fincaId = x.fincaId, loteId = x.loteId, lote = x.lote, techado = x.techado, fecha_inicio = x.fecha_inicio, fecha_fin = x.fecha_fin, metros = x.metros, altura = x.altura, ancho = x.ancho, factor_manzana = x.factor_manzana, densidad = x.densidad, nombre = x.nombre, descripcion = x.descripcion, estado = x.estado }).ToList(); } } catch (Exception e) { throw e; } return(list); }
//metodo para guardar lote y detalle lote public string Save(CreateSubLoteDto model) { var rpta = ""; try { using (var ctx = new PresupuestoContext()) { using (DbContextTransaction transaction = ctx.Database.BeginTransaction()) { try { var sublote = new SPSubLote { Id = model.Id, codigo = model.codigo, nombre = model.nombre, loteId = model.loteId, cultivoId = model.cultivoId, variedadId = model.variedadId, metros = model.metros, altura = model.altura, ancho = model.ancho, densidad = model.densidad, factor_manzana = model.factor_manzana, techado = model.techado, fecha_inicio = model.fecha_inicio, fecha_fin = model.fecha_fin, estado = "A" }; if (sublote.Id > 0) { ctx.Entry(sublote).State = EntityState.Modified; } else { ctx.SPSubLote.Add(sublote); } ctx.SaveChanges(); transaction.Commit(); rpta = "Lote registado correctamente"; } catch (Exception ex) { transaction.Rollback(); throw ex; } } } } catch (Exception e) { throw e; } return(rpta); }
//metodo para guardar lote y detalle lote public string Save(CentroCostoDto model, string op) { var rpta = ""; try { using (var ctx = new PresupuestoContext()) { using (DbContextTransaction transaction = ctx.Database.BeginTransaction()) { try { var ccosto = new CentrodeCosto { codigo = model.codigo, descripcion = model.descripcion, Region = model.Region, CorrelativoTD = model.CorrelativoTD, Correlativo = model.Correlativo, CodigoNAV = model.CodigoNAV, paisId = model.paisId, estado = "A" }; if (op == "G") { ctx.CentrodeCosto.Add(ccosto); } else { ctx.Entry(ccosto).State = EntityState.Modified; } ctx.SaveChanges(); transaction.Commit(); rpta = "Centro de costo registado correctamente"; } catch (Exception ex) { transaction.Rollback(); throw ex; } } } } catch (Exception e) { throw e; } return(rpta); }
//obtener detalles por id public List <SPDetallePresupuesto> GetByPresupuesto(int presupuestoId) { var list = new List <SPDetallePresupuesto>(); try { using (var ctx = new PresupuestoContext()) { list = ctx.SPDetallePresupuesto.Where(x => x.presupuestoId == presupuestoId).ToList(); } } catch { } return(list); }
//obtener por id public SPActividad GetById(int id) { var actividad = new SPActividad(); try { using (var ctx = new PresupuestoContext()) { actividad = ctx.SPActividad.Where(x => x.Id == id).SingleOrDefault(); } }catch (Exception e) { throw e; } return(actividad); }
public List <SPProductoPresentacion> GetDetalles(int id) { var list = new List <SPProductoPresentacion>(); try { using (var ctx = new PresupuestoContext()) { list = ctx.SPProductoPresentacion.Where(x => x.productoId == id).ToList(); } } catch { } return(list); }
public List <SPUsuario> GetAll() { var list = new List <SPUsuario>(); try { using (var ctx = new PresupuestoContext()) { list = ctx.SPUsuario.ToList(); } }catch (Exception) { } return(list); }
//obtener todos los sublotes public List <SPSubLote> GetAllSublotes() { var list = new List <SPSubLote>(); try { using (var ctx = new PresupuestoContext()) { list = ctx.SPSubLote.Where(x => x.estado == "A").ToList(); } }catch (Exception e) { throw e; } return(list); }
//obtener por id public SPTipoCambio GetById(int id) { var tipo = new SPTipoCambio(); try { using (var ctx = new PresupuestoContext()) { tipo = ctx.SPTipoCambio.Where(x => x.Id == id).SingleOrDefault(); } } catch (Exception e) { throw e; } return(tipo); }