Пример #1
0
        private static void CreateEstadaInTime()
        {
            Hóspede responsável     = new Hóspede();
            Hóspede hóspede         = new Hóspede();
            Estada  estada          = new Estada();
            Extra   extraPessoal    = new Extra();
            Extra   extraAlojamento = new Extra();

            Console.Write("NIF Hóspede Responsável: ");
            responsável.NIF = int.Parse(Console.ReadLine());

            Console.Write("NIF Hóspede Acompanhante: ");
            hóspede.NIF = int.Parse(Console.ReadLine());

            Console.Write("Data Inicial da Estada(YYYY-MM-DD HH:MM:SS): ");
            estada.dataInício = Convert.ToDateTime(Console.ReadLine());

            Console.Write("Data Final da Estada(YYYY-MM-DD HH:MM:SS): ");
            estada.dataFim = Convert.ToDateTime(Console.ReadLine());

            Console.Write("Tipo de Alojamento(tenda/bungalow): ");
            string tipoAloj = Console.ReadLine();

            Console.Write("Lotação de pessoas: ");
            int lot = int.Parse(Console.ReadLine());

            Console.Write("Identificador extra pessoal: ");
            extraPessoal.id        = int.Parse(Console.ReadLine());
            extraPessoal.associado = "pessoa";

            Console.Write("Identificador extra alojamento: ");
            extraAlojamento.id        = int.Parse(Console.ReadLine());
            extraAlojamento.associado = "alojamento";

            if (tipoAloj.Equals("tenda"))
            {
                using (Context context = new Context(connectionString)) {
                    Tenda tenda = new Tenda();
                    tenda.númeroMáximoPessoas = lot;
                    tenda.tipoAlojamento      = "tenda";
                    ProcUtils procedimento = new ProcUtils(context);
                    procedimento.createEstadaInTime(responsável, hóspede, estada, tenda, extraPessoal, extraAlojamento);
                }
            }
            else
            {
                using (Context context = new Context(connectionString)) {
                    Bungalow bungalow = new Bungalow();
                    bungalow.númeroMáximoPessoas = lot;
                    bungalow.tipoAlojamento      = "bungalow";
                    ProcUtils procedimento = new ProcUtils(context);
                    procedimento.createEstadaInTime(responsável, hóspede, estada, bungalow, extraPessoal, extraAlojamento);
                }
            }
        }
Пример #2
0
        private static void UpdateExtra(string tipoExtra)
        {
            Extra extra = new Extra();

            Console.Write("Id: ");
            extra.id = int.Parse(Console.ReadLine());

            Console.Write("Descrição: ");
            extra.descrição = Console.ReadLine();

            Console.Write("Preço Dia: ");
            extra.preçoDia = int.Parse(Console.ReadLine());

            if (tipoExtra.Equals("3"))
            {
                using (var context = new GlampinhoEF()) {
                    extra.associado = "alojamento";

                    context.Extra.Attach(extra);

                    var entry = context.Entry(extra);
                    entry.Property(e => e.descrição).IsModified = true;
                    entry.Property(e => e.preçoDia).IsModified  = true;
                    entry.Property(e => e.associado).IsModified = true;
                    context.SaveChanges();
                }
            }
            else
            {
                using (var context = new GlampinhoEF()) {
                    extra.associado = "pessoa";

                    context.Extra.Attach(extra);

                    var entry = context.Entry(extra);
                    entry.Property(e => e.descrição).IsModified = true;
                    entry.Property(e => e.preçoDia).IsModified  = true;
                    entry.Property(e => e.associado).IsModified = true;
                    context.SaveChanges();
                }
            }
        }