public static string createPagares(Inscripcion inscripcion)
        {
            string           sql, Output = string.Empty;
            NpgsqlConnection cnn;

            cnn = new NpgsqlConnection(connectionString);
            NpgsqlCommand command;

            Arancel arancel    = ArancelRepository.getAranceles(inscripcion.InstitucionID.ToString()).Where(x => x.ID == inscripcion.ArancelID).SingleOrDefault();
            decimal montocuota = Convert.ToDecimal(arancel.MatriculaAnual.Replace(".", string.Empty)) / inscripcion.CantidadCuotas;

            for (var i = 0; i <= inscripcion.CantidadCuotas; i++)
            {
                try
                {
                    string  titulo = i == 0 ? "INSCRIPCION" : "CUOTA";
                    decimal monto  = i == 0 ? Convert.ToInt64(arancel.MontoInscripcion.Replace(".", "")) : montocuota;

                    sql = $"insert into dbo.pagare(idinscripcion, tipopagare, estado, monto,  descripcion) " +
                          $"values ({inscripcion.ID}, '{titulo}',  " +
                          $"'PE', {monto}, '{ titulo + (i == 0 ? "" : $" - {i} / {inscripcion.CantidadCuotas}") }') ";

                    cnn.Open();
                    command = new NpgsqlCommand(sql, cnn);
                    command.ExecuteNonQuery();
                    command.Dispose(); cnn.Close();
                }
        public static string createArancel(Arancel arancel)
        {
            string mensaje = string.Empty;

            try
            {
                NpgsqlConnection cnn;
                cnn = new NpgsqlConnection(connectionString);
                cnn.Open();

                NpgsqlCommand command;
                string        sql, Output = string.Empty;

                decimal montodecimal     = Convert.ToDecimal(arancel.MontoInscripcion.Replace(".", string.Empty));
                decimal matriculadecimal = Convert.ToDecimal(arancel.MatriculaAnual.Replace(".", string.Empty));
                int     anho             = Convert.ToInt32(arancel.AnhoLectivo.Replace(".", string.Empty));

                sql = $"insert into dbo.arancel(monto_inscripcion, matricula_anual, anho_lectivo, observacion, nombre_arancel, idinstitucion) " +
                      $"values ({montodecimal}, '{matriculadecimal}', '{anho}', '{arancel.Observacion}', '{arancel.NombreArancel}', '{arancel.InstitucionId}')";

                command = new NpgsqlCommand(sql, cnn);
                command.ExecuteNonQuery();
                mensaje = "OK";
                command.Dispose(); cnn.Close();
            }

            catch (Exception e)
            {
                mensaje = "Ha ocurrido un error al insertar el arancel.";
            }

            return(mensaje);
        }
        public ActionResult Eliminar(string id)
        {
            var            longid    = Convert.ToInt64(id);
            List <Arancel> aranceles = (List <Arancel>)Session["aranceles"];
            Arancel        arancel   = aranceles.Where(x => x.ID == longid).SingleOrDefault();

            return(View(arancel));
        }
        public ActionResult Crear(Arancel arancel)
        {
            arancel.InstitucionId = Convert.ToInt64(HttpContext.Session["institucion"].ToString());
            var mensaje = ArancelRepository.createArancel(arancel);

            if (mensaje == "OK")
            {
                ViewBag.mensaje = "La carga se realizó exitosamente.";
            }
            else
            {
                ViewBag.error = mensaje;
            }
            return(View());
        }
        public ActionResult Editar(Arancel arancel)
        {
            arancel.InstitucionId = Convert.ToInt64(HttpContext.Session["institucion"].ToString());
            var mensaje = ArancelRepository.updateArancel(arancel);

            if (mensaje == "OK")
            {
                ViewBag.mensaje = "La carga se editó exitosamente.";
            }
            else
            {
                ViewBag.error = mensaje;
            }

            return(RedirectToAction("Index"));
        }
        public static string updateArancel(Arancel arancel)
        {
            string mensaje = string.Empty;

            try
            {
                NpgsqlConnection cnn;
                cnn = new NpgsqlConnection(connectionString);
                cnn.Open();

                NpgsqlCommand command;
                string        sql, Output = string.Empty;

                decimal montodecimal     = Convert.ToDecimal(arancel.MontoInscripcion.Replace(".", string.Empty));
                decimal matriculadecimal = Convert.ToDecimal(arancel.MatriculaAnual.Replace(".", string.Empty));
                int     anho             = Convert.ToInt32(arancel.AnhoLectivo.Replace(".", string.Empty));

                sql = $"update dbo.arancel set " +
                      $"monto_inscripcion = {montodecimal}, matricula_anual = {matriculadecimal}, anho_lectivo ={anho}, " +
                      $"observacion = '{arancel.Observacion}', nombre_arancel = '{arancel.NombreArancel}',  " +
                      $"idinstitucion = '{arancel.InstitucionId}' " +
                      $"where id = {arancel.ID}";

                command = new NpgsqlCommand(sql, cnn);
                command.ExecuteNonQuery();
                mensaje = "OK";
                command.Dispose(); cnn.Close();
            }

            catch (Exception e)
            {
                mensaje = "Ha ocurrido un error al insertar el usuario.";
            }

            return(mensaje);
        }