Exemple #1
0
        public void updateVacinacao(Vacinacao vacinacao)
        {
            try
            {
                this.conn.openConnection();
                string     sql = "UPDATE vacinacao SET veterinario_id = @veterinario ,animal_id = @animal WHERE id= @vacinacao";
                SqlCommand cmd = new SqlCommand();
                cmd.Connection  = this.conn.SqlConn;
                cmd.CommandText = sql;

                cmd.Parameters.AddWithValue("@veterinario", vacinacao.Veterinario.Id);
                cmd.Parameters.AddWithValue("@animal", vacinacao.Animal.Id);
                cmd.Parameters.AddWithValue("@vacinacao", vacinacao.Id);

                cmd.ExecuteNonQuery();

                this.conn.closeConnection();

                this.updateDoseVacina(vacinacao);
            }
            catch (SqlException ce)
            {
                throw new DaoException("Erro ao Inserir Usuario :" + ce.Message);
            }
        }
Exemple #2
0
        public void updateDoseVacina(Vacinacao vacinacao)
        {
            try
            {
                this.conn.openConnection();


                foreach (DoseVacina doseVacina in vacinacao.LDoseVacina)
                {
                    string     sql = "UPDATE dose_vacina SET dose_id = @dose , vacina_id = @vacina ,vacinacao_id = @vacinacao  ,  data_proxima_aplicacao = @proxima_aplicacao WHERE  id= @dose_vacina";
                    SqlCommand cmd = new SqlCommand();
                    cmd.Connection  = this.conn.SqlConn;
                    cmd.CommandText = sql;
                    cmd.Parameters.AddWithValue("@dose", doseVacina.Dose.Id);
                    cmd.Parameters.AddWithValue("@vacina", doseVacina.Vacina.Id);
                    cmd.Parameters.AddWithValue("@vacinacao", vacinacao.Id);
                    cmd.Parameters.AddWithValue("@proxima_aplicacao", doseVacina.ProximaAplicacao);
                    cmd.Parameters.AddWithValue("@dose_vacina", doseVacina.Id);
                    cmd.ExecuteNonQuery();
                }


                this.conn.closeConnection();
            }
            catch (SqlException ce)
            {
                throw new DaoException("Erro ao alterar Dose vacina :" + ce.Message);
            }
        }
Exemple #3
0
        public void insertDoseVacina(Vacinacao vacinacao)
        {
            try
            {
                this.conn.openConnection();

                DoseDaoImp doseDao = new DoseDaoImp();

                foreach (DoseVacina doseVacina in vacinacao.LDoseVacina)
                {
                    doseVacina.Dose.Id = doseDao.insertDose(doseVacina.Dose);

                    string     sql = "INSERT INTO dose_vacina(dose_id , vacina_id ,vacinacao_id ,data_aplicacao ,  data_proxima_aplicacao ) VALUES (@dose , @vacina , @vacinacao , CURRENT_TIMESTAMP , @proxima_aplicacao)";
                    SqlCommand cmd = new SqlCommand();
                    cmd.Connection = this.conn.SqlConn;

                    cmd.CommandText = sql;
                    cmd.Parameters.AddWithValue("@dose", doseVacina.Dose.Id);
                    cmd.Parameters.AddWithValue("@vacina", doseVacina.Vacina.Id);
                    cmd.Parameters.AddWithValue("@vacinacao", vacinacao.Id);
                    cmd.Parameters.AddWithValue("@proxima_aplicacao", doseVacina.ProximaAplicacao);
                    cmd.ExecuteNonQuery();
                }

                this.conn.closeConnection();
            }
            catch (SqlException ce)
            {
                throw new DaoException("Erro ao Inserir Dose vacina :" + ce.Message);
            }
        }
        public async Task <ActionResult> Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Vacinacao vacinacao = await db.Vacinacoes.FindAsync(id);

            if (vacinacao == null)
            {
                return(HttpNotFound());
            }
            ViewBag.AnimalId = new SelectList(repoAnimal.GetAll(), "ID", "Nome", vacinacao.AnimalId);
            ViewBag.VacinaId =
                repoVacina.GetAll()
                .Select(
                    a =>
                    new SelectListItem()
            {
                Text     = a.Descricao,
                Value    = a.Id.ToString(),
                Selected = a.Id == vacinacao.VacinaId
            });
            return(PartialView("_Edit", vacinacao));
        }
Exemple #5
0
        public void insertVacinacao(Vacinacao vacinacao)
        {
            try
            {
                this.conn.openConnection();
                string     sql = "INSERT INTO vacinacao(veterinario_id,animal_id,data_vacinacao) OUTPUT INSERTED.ID  VALUES (@veterinario , @animal , CURRENT_TIMESTAMP);";
                SqlCommand cmd = new SqlCommand();
                cmd.Connection  = this.conn.SqlConn;
                cmd.CommandText = sql;

                cmd.Parameters.AddWithValue("@veterinario", vacinacao.Veterinario.Id);
                cmd.Parameters.AddWithValue("@animal", vacinacao.Animal.Id);

                int vacinacaoId = (int)cmd.ExecuteScalar();

                vacinacao.Id = vacinacaoId;

                this.insertDoseVacina(vacinacao);



                this.conn.closeConnection();
            }
            catch (SqlException ce)
            {
                throw new DaoException("Erro ao Inserir Usuario :" + ce.Message);
            }
        }
        public ActionResult Create([Bind(Include = "ID,DataPrevisao,DataVacinacao,VacinaId,AnimalId")] Vacinacao vacinacao)
        {
            if (ModelState.IsValid)
            {
                var vacina = repoVacina.Find(vacinacao.VacinaId);
                for (var dose = 1; dose <= vacina.Doses; dose++)
                {
                    if (dose == 1)
                    {
                        vacinacao.DataPrevisao  = DateTime.Now.Date;
                        vacinacao.DataVacinacao = DateTime.Now.Date;
                    }
                    else
                    {
                        vacinacao.DataPrevisao  = DateTime.Now.Date.AddDays(vacina.IntervaloDias * (dose - 1));
                        vacinacao.DataVacinacao = null;
                    }
                    repoVacinacao.Adicionar(vacinacao);
                    repoVacinacao.SalvarTodos();
                }

                return(Json(new { success = true }));
            }


            return(PartialView("_Create"));
        }
        public ActionResult DeleteConfirmed(string id)
        {
            NewRepository();
            Vacinacao vacinacao = repository.GetVacinacaoByID(id);

            repository.DeleteVacinacao(vacinacao.Id);
            return(RedirectToAction("Index"));
        }
        public ActionResult DeleteConfirmed(int id)
        {
            Vacinacao vacinacao = repoVacinacao.Find(id);

            repoVacinacao.Excluir(x => x == vacinacao);
            repoVacinacao.SalvarTodos();
            return(Json(new { success = true }));
        }
Exemple #9
0
        public List <DoseVacina> getDoseVacina(Vacinacao vacinacao)
        {
            try
            {
                this.conn.openConnection();

                //cmd.CommandText =
                List <DoseVacina> lDoseVacina = new List <DoseVacina>();
                SqlCommand        cmd         = new SqlCommand();

                string sql = " SELECT dv.id, dv.dose_id ,dv.vacina_id  , dv.data_proxima_aplicacao , dv.data_aplicacao ";
                sql += " , d.dosagem , d.numero ,d.medida ,d.data_cadastro as dose_data_cadastro, v.nome , v.descricao ";
                sql += " FROM dose_vacina dv INNER JOIN  dose d ON dv.dose_id = d.id ";
                sql += " INNER JOIN vacina v ON dv.vacina_id = v.id WHERE vacinacao_id = @vacinacao";

                cmd.CommandText = sql;
                cmd.Connection  = this.conn.SqlConn;
                cmd.Parameters.AddWithValue("@vacinacao", vacinacao.Id);
                SqlDataReader reader = cmd.ExecuteReader();
                while (reader.Read())
                {
                    DoseVacina doseVacina = new DoseVacina();
                    // dose
                    Dose dose = new Dose();

                    dose.Id           = reader.GetInt32(reader.GetOrdinal("dose_id"));
                    dose.Dosagem      = (float)reader.GetDouble(reader.GetOrdinal("dosagem"));
                    dose.Numero       = reader.GetInt32(reader.GetOrdinal("numero"));
                    dose.Medida       = reader.GetString(reader.GetOrdinal("medida"));
                    dose.DataCadastro = reader.GetDateTime(reader.GetOrdinal("dose_data_cadastro"));

                    doseVacina.Dose = dose;
                    // vacina
                    Vacina vacina = new Vacina();

                    vacina.Id        = reader.GetInt32(reader.GetOrdinal("vacina_id"));
                    vacina.Nome      = reader.GetString(reader.GetOrdinal("nome"));
                    vacina.Descricao = reader.GetString(reader.GetOrdinal("descricao"));

                    doseVacina.Vacina = vacina;

                    doseVacina.DataAplicacao    = reader.GetDateTime(reader.GetOrdinal("data_aplicacao"));
                    doseVacina.ProximaAplicacao = reader.GetDateTime(reader.GetOrdinal("data_proxima_aplicacao"));


                    lDoseVacina.Add(doseVacina);
                }

                this.conn.closeConnection();


                return(lDoseVacina);
            }
            catch (SqlException ce)
            {
                throw new DaoException("Erro ao listar Dose vacina :" + ce.Message);
            }
        }
        public ActionResult Create(int AnimalID)
        {
            var vacinacao = new Vacinacao();

            vacinacao.AnimalId = AnimalID;
            ViewBag.VacinaId   = new SelectList(repoVacina.GetAll().ToList(), "ID", "Descricao");
            ViewBag.AnimalId   = new SelectList(repoAnimal.GetAll().ToList(), "ID", "Nome");
            return(PartialView("_Create", vacinacao));
        }
Exemple #11
0
 public void InsertVacinacao(Vacinacao Vacinacao)
 {
     if (string.IsNullOrEmpty(Vacinacao.Id))
     {
         var guid = Guid.NewGuid(); Vacinacao.Id = guid.ToString();
     }
     DBcontext.Vacinacao.Add(Vacinacao);
     Save();
 }
 public ActionResult Edit([Bind(Include = "Id,Nome,Data,Informacoes")] Vacinacao vacinacao)
 {
     if (ModelState.IsValid)
     {
         NewRepository();
         repository.UpdateVacinacao(vacinacao);
         return(RedirectToAction("Index"));
     }
     return(View(vacinacao));
 }
        public async Task <ActionResult> Edit([Bind(Include = "ID,DataPrevisao,DataVacinacao,VacinaId,AnimalId")] Vacinacao vacinacao)
        {
            if (ModelState.IsValid)
            {
                using (var ctx = new BancoContexto()) {
                    ctx.Entry(vacinacao).State = EntityState.Modified;
                    await ctx.SaveChangesAsync();

                    return(Json(new { success = true }));
                }
            }
            return(PartialView("_Edit", vacinacao));
        }
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Vacinacao vacinacao = repoVacinacao.Find(id);

            if (vacinacao == null)
            {
                return(HttpNotFound());
            }
            return(View(vacinacao));
        }
        public async Task <ActionResult> Delete(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Vacinacao vacinacao = db.Vacinacoes.Find(id);

            if (vacinacao == null)
            {
                return(HttpNotFound());
            }
            return(PartialView("_Delete", vacinacao));
        }
        public ActionResult Edit(string id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            Vacinacao vacinacao = repository.GetVacinacaoByID(id);

            if (vacinacao == null)
            {
                return(HttpNotFound());
            }

            return(View(vacinacao));
        }
Exemple #17
0
 public void deletar(Vacinacao vacinacao)
 {
     try
     {
         if (vacinacao.Equals(null) || vacinacao.Equals(""))
         {
             throw new Exception("Objeto vacinacao Nulo");
         }
         this.vacinacaoDao.deleteVacinacao(vacinacao);
     }
     catch (ConexaoException c)
     {
         throw new GeralException(c.Message);
     }
     catch (DaoException d)
     {
         throw new GeralException(d.Message);
     }
 }
Exemple #18
0
        public void deleteVacinacao(Vacinacao vacinacao)
        {
            try
            {
                this.conn.openConnection();
                string sql = "DELETE FROM vacinacao WHERE id = @vacinacao";

                SqlCommand cmd = new SqlCommand();
                cmd.Connection  = this.conn.SqlConn;
                cmd.CommandText = sql;

                cmd.Parameters.AddWithValue("@vacinacao", vacinacao.Id);

                cmd.ExecuteNonQuery();
                this.conn.closeConnection();
            }
            catch (SqlException ce)
            {
                throw new DaoException("Erro ao Deletar Vacinacao :" + ce.Message);
            }
        }
Exemple #19
0
        public List <Vacinacao> listVacinacaoForAnimal(Animal animal)
        {
            try
            {
                this.conn.openConnection();

                List <Vacinacao> lVacinacao = new List <Vacinacao>();
                SqlCommand       cmd        = new SqlCommand();
                cmd.CommandText = "SELECT id,veterinario_id,animal_id,data_vacinacao FROM vacinacao WHERE animal_id = @animal";
                cmd.Connection  = this.conn.SqlConn;
                cmd.Parameters.AddWithValue("@animal", animal.Id);
                SqlDataReader reader = cmd.ExecuteReader();
                while (reader.Read())
                {
                    Vacinacao vacinacao = new Vacinacao();
                    vacinacao.Id = reader.GetInt32(reader.GetOrdinal("id"));

                    int animalId = reader.GetInt32(reader.GetOrdinal("animal_id"));
                    vacinacao.Animal = this.animalImp.getAnimal(animalId);

                    int veterinarioId = reader.GetInt32(reader.GetOrdinal("veterinario_id"));
                    vacinacao.Veterinario = this.veterinarioImp.getVeterinario(veterinarioId);

                    vacinacao.LDoseVacina = this.getDoseVacina(vacinacao);


                    lVacinacao.Add(vacinacao);
                }

                this.conn.closeConnection();


                return(lVacinacao);
            }
            catch (SqlException ce)
            {
                throw new DaoException("Erro ao Inserir Dose vacina :" + ce.Message);
            }
        }
Exemple #20
0
 public void UpdateVacinacao(Vacinacao Vacinacao)
 {
     DBcontext.Entry(Vacinacao).State = EntityState.Modified;
     Save();
 }