Exemple #1
0
        public void AddSocioCategoria(SociosCategorias socioCate, SociosCostos socioCosto)
        {
            try
            {
                using (var context = new AEPEntities())
                {
                    context.SociosCategorias.AddObject(socioCate);

                    context.SaveChanges();

                    socioCosto.SociosCategorias = socioCate;

                    context.SociosCostos.AddObject(socioCosto);

                    context.SaveChanges();
                }
            }
            catch (Exception ex)
            {
                if (ex.InnerException.Message.Contains("uniqueSocioCategoria"))
                    throw new Exception("Error: no puede asignar otra categoría sin previamente haber dado de baja al anterior.");
            }
        }
Exemple #2
0
        public void UpdateSocioCategoria(SociosCostos socio)
        {
            try
            {
                using (var context = new AEPEntities())
                {
                    SociosCostos socioUp =
                        context.SociosCostos.Include("SociosCategorias")
                               .First(i => i.SocioCostoId == socio.SocioCostoId);

                    if (socioUp.FechaDesde == socio.FechaDesde)
                    {
                        socioUp.SociosCategorias.Descripcion = socio.SociosCategorias.Descripcion;
                        socioUp.SociosCategorias.Abreviatura = socio.SociosCategorias.Abreviatura;
                        socioUp.SociosCategorias.Valor = socio.SociosCategorias.Valor;
                        socioUp.Valor = socio.Valor;
                        socioUp.Observaciones = socio.Observaciones;
                    }
                    else
                    {
                        socioUp.SociosCategorias.Descripcion = socio.SociosCategorias.Descripcion;
                        socioUp.SociosCategorias.Abreviatura = socio.SociosCategorias.Abreviatura;
                        socioUp.SociosCategorias.Valor = socio.SociosCategorias.Valor;
                        socioUp.FechaHasta = socio.FechaDesde.AddDays(-1);

                        SociosCostos socioNew = new SociosCostos();

                        socioNew.SocioCategoriaId = socio.SociosCategorias.SocioCategoriaId;
                        socioNew.Valor = socio.Valor;
                        socioNew.FechaDesde = socio.FechaDesde;

                        context.SociosCostos.AddObject(socioNew);
                    }
                    context.SaveChanges();
                }
            }
            catch (Exception ex)
            {
                if (ex.InnerException.Message.Contains("uniqueSocioCategoria"))
                    throw new Exception("Error: no puede asignar otra categoría sin previamente haber dado de baja al anterior.");
            }
        }