public List <SalaDTO> ListarSalasPorLocal(int LocalId) { var lstSalas = new List <SalaDTO>(); try { IDbCommand command = conn.CreateCommand(); command.CommandText = $"select * from salas where LocalId = {LocalId}"; IDataReader res = command.ExecuteReader(); while (res.Read()) { var sala = new SalaDTO { Id = Convert.ToInt32(res["Id"]), Nome = Convert.ToString(res["Nome"]) }; lstSalas.Add(sala); } } catch (Exception ex) { throw new Exception(ex.Message); } finally { conn.Close(); } return(lstSalas); }
public SalaDTO ListarSala(int Id) { var sala = new SalaDTO(); try { IDbCommand command = conn.CreateCommand(); command.CommandText = $"select * from salas where Id = {Id}"; IDataReader res = command.ExecuteReader(); while (res.Read()) { sala.Id = Convert.ToInt32(res["Id"]); sala.Nome = Convert.ToString(res["Nome"]); sala.LocalId = Convert.ToInt32(res["LocalId"]); } } catch (Exception ex) { throw new Exception(ex.Message); } finally { conn.Close(); } return(sala); }
public IHttpActionResult Put(int Id, SalaDTO sala) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } try { SalaModel sl = new SalaModel(); if (Id == 0) { sl.Inserir(sala); } else { sl.Editar(sala); } return(Ok("Executado com sucesso!")); } catch (Exception ex) { return(InternalServerError(ex)); } }
public int delete(SalaDTO salaDTO) { int retorno = 0; string sql = "DELETE FROM Sala WHERE salaID=@salaID"; SqlConnection con = new SqlConnection(connectionString); SqlCommand cmd = new SqlCommand(sql, con); cmd.Parameters.AddWithValue("@salaID", salaDTO.salaID); cmd.CommandType = CommandType.Text; con.Open(); try { retorno = cmd.ExecuteNonQuery(); } catch (Exception ex) { retorno = 0; } finally { con.Close(); } return(retorno); }
public int actualizar(SalaDTO salaDTO) { int retorno = 0; SqlConnection conn = new SqlConnection(connectionString); string sql = "UPDATE INTO Sala ( numero, descripcion, unidadID) values( @numero, @descripcion, @unidadID)"; SqlCommand sqlcmd = new SqlCommand(sql, conn); sqlcmd.Parameters.AddWithValue("@numero", salaDTO.numero); sqlcmd.Parameters.AddWithValue("@descripcion", salaDTO.descripcion); sqlcmd.Parameters.AddWithValue("@unidadID", salaDTO.unidadID); sqlcmd.CommandType = CommandType.Text; conn.Open(); try { retorno = sqlcmd.ExecuteNonQuery(); } catch { retorno = 0; } finally { conn.Close(); } return(retorno); }
public void EditarSala(SalaDTO sala) { try { IDbCommand command = conn.CreateCommand(); command.CommandText = "update Salas set Nome = @Nome, LocalId = @LocalId where Id = @Id"; IDbDataParameter Id = new SqlParameter("Id", sala.Id); IDbDataParameter Nome = new SqlParameter("Nome", sala.Nome); IDbDataParameter LocalId = new SqlParameter("LocalId", sala.LocalId); command.Parameters.Add(Id); command.Parameters.Add(Nome); command.Parameters.Add(LocalId); command.ExecuteNonQuery(); } catch (Exception ex) { throw new Exception(ex.Message); } finally { conn.Close(); } }
public DataTable read(SalaDTO salaDTO) { DataTable dt = new DataTable(); SqlConnection conn = new SqlConnection(connectionString); string sql = "SELECT * FROM Sala WHERE salaID = @salaID"; SqlCommand sqlcmd = new SqlCommand(sql, conn); sqlcmd.Parameters.Add(new SqlParameter("@salaID", SqlDbType.Int)); sqlcmd.Parameters["@salaID"].Value = salaDTO.salaID; try { conn.Open(); SqlDataReader rdr = sqlcmd.ExecuteReader(); dt.Load(rdr); rdr.Close(); } catch { dt = null; } finally { conn.Close(); } return(dt); }
public List <SalaDTO> ListarSalas() { var lstSalas = new List <SalaDTO>(); try { IDbCommand command = conn.CreateCommand(); command.CommandText = "select * from salas"; IDataReader res = command.ExecuteReader(); while (res.Read()) { LocalDTO lc = new LocalDTO(); LocalDAO lDAO = new LocalDAO(); int LocalId = 0; if (res["LocalId"] != DBNull.Value) { LocalId = Convert.ToInt32(res["LocalId"]); } lc = lDAO.ListarLocal(LocalId); var sala = new SalaDTO { Id = Convert.ToInt32(res["Id"]), Nome = Convert.ToString(res["Nome"]), LocalId = 0 }; if (lc != null) { sala = new SalaDTO { Id = Convert.ToInt32(res["Id"]), Nome = Convert.ToString(res["Nome"]), LocalId = LocalId, Local = new LocalDTO { Id = LocalId, Nome = lc.Nome } }; } lstSalas.Add(sala); } } catch (Exception ex) { throw new Exception(ex.Message); } finally { conn.Close(); } return(lstSalas); }
public async Task <SalaDTO> CreateAsync(SalaDTO salaDto) { var sala = salaDto.MapToModel(); await salaRepository.AddSalaAsync(sala); return(sala.MapToDto()); }
public static Sala MapToNewValues(this Sala currentValue, SalaDTO newValue) { currentValue.Nome = newValue.Nome; currentValue.Cinema = newValue.Cinema; currentValue.Cidade = newValue.Cidade; return(currentValue); }
public async Task <bool> UpdateAsync(string Id, SalaDTO salaDto) { var currentSala = await salaRepository.GetSalaAsync(Id); currentSala.MapToNewValues(salaDto); return(await salaRepository.UpdateSalaAsync(Id, currentSala)); }
public void Inserir(SalaDTO dto) { dal.Conectar(); string query = "Insert into Sala(nome) values ('" + dto.Nome + "')"; dal.ExecutarComandoSQL(query); }
public int create(SalaDTO salaDTO) { int retorno = 0; SalaDAO salaDAO = new SalaDAO(); retorno = salaDAO.create(salaDTO); return(retorno); }
public int delete(SalaDTO salaDTO) { int retorno = 0; SalaDAO salaDAO = new SalaDAO(); retorno = salaDAO.delete(salaDTO); return(retorno); }
public SalaDTO MapperToDTO(Sala Sala) { SalaDTO SalaDTO = new SalaDTO { Id = Sala.Id , Nome = Sala.Nome }; return(SalaDTO); }
public void Inserir(SalaDTO sala) { try { SalaDAO salaDAO = new SalaDAO(); salaDAO.InserirSala(sala); } catch (Exception ex) { throw new Exception("Erro ao inserir sala: " + ex.Message); } }
public void Editar(SalaDTO sala) { try { SalaDAO salaDAO = new SalaDAO(); salaDAO.EditarSala(sala); } catch (Exception ex) { throw new Exception("Erro ao editar sala: " + ex.Message); } }
public Sala MapperToEntity(SalaDTO SalaDTO) { Sala Sala = new Sala { Id = SalaDTO.Id , Nome = SalaDTO.Nome , }; return(Sala); }
public async Task <ActionResult <SalaDTO> > Atualizar([FromBody] SalaDTO salaDTO) { if (!ModelState.IsValid) { return(BadRequest()); } var sala = _iMapper.Map <Sala>(salaDTO); await _salaService.Adicionar(sala); return(Ok(sala)); }
public async Task <ActionResult> PutAsync(string id, [FromBody] SalaDTO salaToUpdate) { var sala = await salaService.GetSalaByIdAsync(id); if (sala == null) { return(NotFound()); } await salaService.UpdateAsync(id, salaToUpdate); return(NoContent()); }
public async Task <SalaDTO> CadastrarSala(SalaDTO dto) { var model = new SalaModel { Descricao = dto.Descricao, Codigo = dto.Codigo, Lugares = dto.Lugares, Disponivel = dto.Disponivel, }; model = await _salaRepository.CriarSala(model); return(dto); }
public static Sala MapToModel(this SalaDTO sala, bool setId = false) { var f = new Sala { Nome = sala.Nome, Cinema = sala.Cinema, Cidade = sala.Cidade }; if (setId) { f.Id = new ObjectId(sala.Id); } return(f); }
public ActionResult Put([FromBody] SalaDTO SalaDTO) { try { if (SalaDTO == null) { return(NotFound()); } _applicationServiceSala.Update(SalaDTO); return(Ok("Sala Atualizada com sucesso!")); } catch (Exception) { throw; } }
public ActionResult Post([FromBody] SalaDTO SalaDTO) { try { if (SalaDTO == null) { return(NotFound()); } _applicationServiceSala.Add(SalaDTO); return(Ok("Sala Cadastrada com sucesso!")); } catch (Exception ex) { throw ex; } }
public ActionResult Delete([FromBody] SalaDTO SalaDTO) { try { if (SalaDTO == null) { return(NotFound()); } _applicationServiceSala.Remove(SalaDTO); return(Ok("Sala Removida com sucesso!")); } catch (Exception ex) { throw ex; } }
private void btCadastrarTurma_Click(object sender, EventArgs e) { if (!string.IsNullOrEmpty(txtSala.Text)) { SalaDTO dto = new SalaDTO(); SalaBLL bll = new SalaBLL(); string sala = txtSala.Text.Replace("'", "''"); dto.Nome = sala; bll.Inserir(dto); MessageBox.Show("Cadastro efetuado com sucesso!", "Sucesso"); LimpaTela(1); } else if (!string.IsNullOrEmpty(txtSerie.Text)) { SerieBLL bll = new SerieBLL(); SerieDTO dto = new SerieDTO(); string serie = txtSerie.Text.Replace("'", "''"); dto.Nome = serie; bll.Inserir(dto); MessageBox.Show("Cadastro efetuado com sucesso!", "Sucesso"); LimpaTela(1); } else if (!string.IsNullOrEmpty(txtTurma.Text)) { TurmaBLL bll = new TurmaBLL(); TurmaDTO dto = new TurmaDTO(); string turma = txtTurma.Text.Replace("'", "''"); dto.Nome = turma; bll.Inserir(dto); MessageBox.Show("Cadastro efetuado com sucesso!", "Sucesso"); LimpaTela(1); } else { MessageBox.Show("Por favor preencha um ou mais campos antes de cadastrar.", "Aviso"); return; } }
public SalaDTO read(SalaDTO salaDTO) { SalaDTO retornoDTO = new SalaDTO(); SalaDAO salaDAO = new SalaDAO(); DataTable dt = new DataTable(); dt = salaDAO.read(salaDTO); foreach (DataRow row in dt.Rows) { retornoDTO.salaID = Convert.ToInt64(row["salaID"].ToString()); retornoDTO.numero = row["numero"].ToString(); retornoDTO.descripcion = row["descripcion"].ToString(); } return(retornoDTO); }
public async Task <SalaDTO> BuscarSala(int codigo) { var model = await _salaRepository.BuscarSala(codigo); if (model == null) { return(null); } var dto = new SalaDTO { Descricao = model.Descricao, Codigo = model.Codigo, Lugares = model.Lugares, Disponivel = model.Disponivel, }; return(dto); }
public IEnumerable <SalaDTO> MapperListSalas(IEnumerable <Sala> Salas) { foreach (var item in Salas) { SalaDTO SalaDTO = new SalaDTO { Id = item.Id , Nome = item.Nome , }; SalaDTOs.Add(SalaDTO); } return(SalaDTOs); }
public async Task <List <SalaDTO> > BuscarSalas(bool?disponivel, int?min, int?max) { var models = await _salaRepository.BuscarSalas(disponivel, min, max); var dtos = new List <SalaDTO>(); foreach (var model in models) { var dto = new SalaDTO { Descricao = model.Descricao, Codigo = model.Codigo, Lugares = model.Lugares, Disponivel = model.Disponivel, }; dtos.Add(dto); } return(dtos); }