Example #1
0
 public ActionResult DeleteAgenda(Agenda pAgenda, int pId)
 {
     try
     {
         AgendaRepository exclui = new AgendaRepository();
         exclui.Delete(pId);
         return RedirectToAction("ListAgendas").ComMensagemDeSucesso("Agendamento excluído com sucesso!");
     }
     catch
     {
         throw;
     }
 }
Example #2
0
        // POST: api/Agenda
        public HttpResponseMessage Post(Agenda pAgenda)
        {
            if (!ModelState.IsValid)
            {
                return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState);
            }

            try
            {
                AgendaRepository create = new AgendaRepository();
                create.Create(pAgenda);
                return Request.CreateResponse(HttpStatusCode.OK);
            }
            catch (ArgumentException ex)
            {
                return Request.CreateErrorResponse(HttpStatusCode.NotFound, ex);
            }
        }
Example #3
0
        // PUT: api/Agenda/5
        public HttpResponseMessage Put(int pId, Agenda pAgenda)
        {
            if (!ModelState.IsValid)
            {
                return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState);
            }

            if (pId != pAgenda.IdAgenda)
            {
                return Request.CreateResponse(HttpStatusCode.BadRequest);
            }

            try
            {
                AgendaRepository update = new AgendaRepository();
                update.Update(pAgenda);
                return Request.CreateResponse(HttpStatusCode.OK);
            }
            catch (ArgumentException ex)
            {
                return Request.CreateErrorResponse(HttpStatusCode.NotFound, ex);
            }
        }
Example #4
0
 public ActionResult CreateAgenda(Agenda pAgenda)
 {
     try
     {
         if (ModelState.IsValid)
         {
             ViewBag.IdTecnico = new SelectList(TecnicoRepository.GetAll(), "IdTecnico", "Nome", pAgenda.IdTecnico);
             ViewBag.IdCliente = new SelectList(ClienteRepository.GetAll(), "IdCliente", "Nome", pAgenda.IdCliente);
             ViewBag.Status = new SelectList(new Agenda().ListStatus(), "Status", "Status", pAgenda.Status);
             AgendaRepository nova = new AgendaRepository();
             nova.Create(pAgenda);
             return RedirectToAction("ListAgendas").ComMensagemDeSucesso("Agendamento cadastrado com sucesso!");
         }
         else
         {
             return View();
         }
     }
     catch
     {
         return RedirectToAction("ListAgendas").ComMensagemDeErro("Agendamento não foi cadastrado! Verifique os dados informados");
         throw;
     }
 }
Example #5
0
        public void Update(Agenda pAgenda)
        {
            StringBuilder sql = new StringBuilder();
            SqlCommand cmd = new SqlCommand();

            sql.Append("UPDATE Agenda SET [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected]");
            sql.Append(" WHERE IdAgenda=" + pAgenda.IdAgenda);

            cmd.Parameters.AddWithValue("@IdTecnico", pAgenda.IdTecnico);
            cmd.Parameters.AddWithValue("@Data", pAgenda.Data);

            if ((pAgenda.Hora) != null)
                cmd.Parameters.Add("@Hora", SqlString.Null).Value = pAgenda.Hora;
            else
                cmd.Parameters.Add("@Hora", SqlString.Null);

            if (!string.IsNullOrEmpty(pAgenda.Local))
                cmd.Parameters.Add("@Local", SqlString.Null).Value = pAgenda.Local;
            else
                cmd.Parameters.Add("@Local", SqlString.Null);

            if (!string.IsNullOrEmpty(pAgenda.Servico))
                cmd.Parameters.Add("@Servico", SqlString.Null).Value = pAgenda.Servico;
            else
                cmd.Parameters.Add("@Servico", SqlString.Null);

            if (!string.IsNullOrEmpty(pAgenda.Observacoes))
                cmd.Parameters.Add("@Observacoes", SqlString.Null).Value = pAgenda.Observacoes;
            else
                cmd.Parameters.Add("@Observacoes", SqlString.Null);

            cmd.Parameters.AddWithValue("@Status", pAgenda.Status);

            cmd.CommandText = sql.ToString();
            SqlConn.CommandPersist(cmd);
        }
Example #6
0
        public void Create(Agenda pAgenda)
        {
            StringBuilder sql = new StringBuilder();
            SqlCommand cmd = new SqlCommand();

            sql.Append("INSERT INTO Agenda (IdTecnico, IdCliente, Data_, Hora, Local_, Servico, Observacoes, Status_)");
            sql.Append("VALUES(@IdTecnico, @IdCliente, @Data, @Hora, @Local, @Servico, @Observacoes, @Status)");

            cmd.Parameters.AddWithValue("@IdTecnico", pAgenda.IdTecnico);
            cmd.Parameters.AddWithValue("@IdCliente", pAgenda.IdCliente);
            cmd.Parameters.AddWithValue("@Data", pAgenda.Data);

            if ((pAgenda.Hora) != null)
                cmd.Parameters.Add("@Hora", SqlString.Null).Value = pAgenda.Hora;
            else
                cmd.Parameters.Add("@Hora", SqlString.Null);

            if (!string.IsNullOrEmpty(pAgenda.Local))
                cmd.Parameters.Add("@Local", SqlString.Null).Value = pAgenda.Local;
            else
                cmd.Parameters.Add("@Local", SqlString.Null);

            if (!string.IsNullOrEmpty(pAgenda.Servico))
                cmd.Parameters.Add("@Servico", SqlString.Null).Value = pAgenda.Servico;
            else
                cmd.Parameters.Add("@Servico", SqlString.Null);

            if (!string.IsNullOrEmpty(pAgenda.Observacoes))
                cmd.Parameters.Add("@Observacoes", SqlString.Null).Value = pAgenda.Observacoes;
            else
                cmd.Parameters.Add("@Observacoes", SqlString.Null);

            cmd.Parameters.AddWithValue("@Status", pAgenda.Status);

            cmd.CommandText = sql.ToString();
            SqlConn.CommandPersist(cmd);
        }
Example #7
0
        public static Agenda GetOne(int pId)
        {
            StringBuilder sql = new StringBuilder();
            Agenda agenda = new Agenda();

            sql.Append("select ag.IdAgenda, ag.IdTecnico, tc.Nome as TecnicoNome, ag.IdCliente, cl.Nome as ClienteNome, ag.Data_, ag.Hora, ag.Local_, ag.Servico, ag.Observacoes, ag.Status_");
            sql.Append(" from Agenda as ag");
            sql.Append(" inner join Cliente as cl");
            sql.Append(" on ag.IdCliente = cl.IdCliente");
            sql.Append(" inner join Tecnico as tc");
            sql.Append(" on ag.IdTecnico = tc.IdTecnico");
            sql.Append(" WHERE ag.IdAgenda = " + pId );

            SqlDataReader dr = SqlConn.Get(sql.ToString());

            while (dr.Read())
            {
                agenda.IdAgenda = (int)dr["IdAgenda"];
                agenda.IdCliente = (int)dr["IdCliente"];
                agenda.ClienteNome = (string)dr["ClienteNome"];
                agenda.IdTecnico = (int)dr["IDTecnico"];
                agenda.TecnicoNome = (string)dr["TecnicoNome"];
                agenda.Data = (DateTime)dr["Data_"];
                agenda.Hora = dr.IsDBNull(dr.GetOrdinal("Hora")) ? null : (DateTime?)dr["Hora"];
                agenda.Local = dr.IsDBNull(dr.GetOrdinal("Local_")) ? "" : (string)dr["Local_"];
                agenda.Servico = dr.IsDBNull(dr.GetOrdinal("Servico")) ? "" : (string)dr["Servico"];
                agenda.Observacoes = dr.IsDBNull(dr.GetOrdinal("Observacoes")) ? "" : (string)dr["Observacoes"];
                agenda.Status = (string)dr["Status_"];
            }
            dr.Close();
            return agenda;
        }
Example #8
0
 public ActionResult EditAgenda(Agenda pAgenda)
 {
     try
     {
         if (ModelState.IsValid)
         {
             ViewBag.IdTecnico = new SelectList(TecnicoRepository.GetAll(), "IdTecnico", "Nome", pAgenda.IdTecnico);
             ViewBag.Status = new SelectList(new Agenda().ListStatus(), "Status", "Status", pAgenda.Status);
             AgendaRepository edit = new AgendaRepository();
             edit.Update(pAgenda);
             return RedirectToAction("ListAgendas").ComMensagemDeSucesso("Agendamento editado com sucesso!");
         }
         else
         {
             return View("EditAgenda");
         }
     }
     catch
     {
         throw;
     }
 }