public void Update(KeyValuePair <int, int> id, Inscriere entity) { IDbConnection connection = DBUtils.getConnection(props); using (var command = connection.CreateCommand()) { command.CommandText = "update Inscrieri set idParticipant=@idParticipant, idProba=@idProba where idParticipant=@idPart and idProba=@idPr"; IDbDataParameter paramIdParticipant = command.CreateParameter(); paramIdParticipant.ParameterName = "@idParticipant"; paramIdParticipant.Value = entity.ID.Key; command.Parameters.Add(paramIdParticipant); IDbDataParameter paramIdProba = command.CreateParameter(); paramIdProba.ParameterName = "@idProba"; paramIdProba.Value = entity.ID.Value; command.Parameters.Add(paramIdProba); IDbDataParameter paramIdPart = command.CreateParameter(); paramIdPart.ParameterName = "@idPart"; paramIdPart.Value = id.Key; command.Parameters.Add(paramIdPart); IDbDataParameter paramIdPr = command.CreateParameter(); paramIdPr.ParameterName = "@idPr"; paramIdPr.Value = id.Value; command.Parameters.Add(paramIdPr); command.ExecuteNonQuery(); } }
//int id, Cursa c,Participant p public Inscriere findOne(int id) { log.InfoFormat("Entering findOne with value {0}", id); IDbConnection con = DBUtils.getConnection(); using (var comm = con.CreateCommand()) { comm.CommandText = "select id,nume, echipa, capacMotor from Inscrieri where id=@id"; IDbDataParameter paramId = comm.CreateParameter(); paramId.ParameterName = "@id"; paramId.Value = id; comm.Parameters.Add(paramId); using (var dataR = comm.ExecuteReader()) { if (dataR.Read()) { int idV = dataR.GetInt32(0); int idCursa = dataR.GetInt32(1); int idParticipant = dataR.GetInt32(2); Participant p = participantDb.findOne(idParticipant); Cursa c = cursaDb.findOne(idCursa); Inscriere inscriere = new Inscriere(id, c, p); log.InfoFormat("Exiting findOne with value {0}", inscriere); return(inscriere); } } } log.InfoFormat("Exiting findOne with value {0}", null); return(null); }
public Inscriere FindOne(int id) { log.InfoFormat("Entering findOne"); IDbConnection con = DBUtils.getConnection(); using (var comm = con.CreateCommand()) { comm.CommandText = "select iid,pid,cid from Inscriere where iid=@iid"; IDbDataParameter paramId = comm.CreateParameter(); paramId.ParameterName = "@iid"; paramId.Value = id; comm.Parameters.Add(paramId); using (var dataR = comm.ExecuteReader()) { if (dataR.Read()) { int iid = dataR.GetInt32(0); int pid = dataR.GetInt32(1); int cid = dataR.GetInt32(2); Inscriere i = new Inscriere(pdr.FindOne(pid), cdr.FindOne(cid)); i.Id = iid; log.InfoFormat("Exiting findOne with value {0}", i); return(i); } } } log.InfoFormat("Exiting findOne with value {0}", null); return(null); }
public void save(Inscriere entity) { var con = DBUtils.getConnection(); using (var comm = con.CreateCommand()) { comm.CommandText = "insert into Inscrieri values (@id, @idCursa, @idParticipant)"; var paramId = comm.CreateParameter(); paramId.ParameterName = "@id"; paramId.Value = entity.Id + 1; comm.Parameters.Add(paramId); var paramIdCursa = comm.CreateParameter(); paramIdCursa.ParameterName = "@idCursa"; paramIdCursa.Value = entity.C.Id; comm.Parameters.Add(paramIdCursa); var paramIdParticipant = comm.CreateParameter(); paramIdParticipant.ParameterName = "@idParticipant"; paramIdParticipant.Value = entity.P.Id; comm.Parameters.Add(paramIdParticipant); var result = comm.ExecuteNonQuery(); if (result == 0) { throw new RepositoryException("No inscriere added !"); } } }
public Inscriere Delete(int id) { log.InfoFormat("Entering Update"); IDbConnection con = DBUtils.getConnection(); Inscriere ins = FindOne(id); using (var comm = con.CreateCommand()) { comm.CommandText = "delete from Inscriere where iid=@iid"; IDbDataParameter paramIid = comm.CreateParameter(); paramIid.ParameterName = "@iid"; paramIid.Value = id; comm.Parameters.Add(paramIid); var result = comm.ExecuteNonQuery(); if (result == 0) { log.InfoFormat("update exited with value {0}", null); return(null); } else { log.InfoFormat("update exited with value {0}", result); return(ins); } } }
public IEnumerable <Inscriere> FindAll() { log.InfoFormat("Entering findAll"); IDbConnection con = DBUtils.getConnection(); IList <Inscriere> inscrieri = new List <Inscriere>(); using (var comm = con.CreateCommand()) { comm.CommandText = "select * from Inscriere"; using (var dataR = comm.ExecuteReader()) { while (dataR.Read()) { int iid = dataR.GetInt32(0); int pid = dataR.GetInt32(1); int cid = dataR.GetInt32(2); Inscriere i = new Inscriere(pdr.FindOne(pid), cdr.FindOne(cid)); i.Id = iid; inscrieri.Add(i); } } } log.InfoFormat("Exiting findAll"); return(inscrieri); }
public IEnumerable <Inscriere> GetInscrieriByIdParticipant(int idParticipant) { log.InfoFormat("Entering GetInscrieriByIdParticipant"); IDbConnection con = DBUtils.getConnection(); IList <Inscriere> inscrieri = new List <Inscriere>(); using (var comm = con.CreateCommand()) { comm.CommandText = "select iid,pid,cid from Inscriere where pid=@pid"; IDbDataParameter paramId = comm.CreateParameter(); paramId.ParameterName = "@pid"; paramId.Value = idParticipant; comm.Parameters.Add(paramId); using (var dataR = comm.ExecuteReader()) { while (dataR.Read()) { int iid = dataR.GetInt32(0); int pid = dataR.GetInt32(1); int cid = dataR.GetInt32(2); Inscriere i = new Inscriere(pdr.FindOne(pid), cdr.FindOne(cid)); i.Id = iid; inscrieri.Add(i); } } } log.InfoFormat("Exiting GetInscrieriByIdParticipant"); return(inscrieri); }
public Inscriere Save(Inscriere entity) { log.InfoFormat("Entering Save"); IDbConnection con = DBUtils.getConnection(); using (var comm = con.CreateCommand()) { comm.CommandText = "Insert into Inscriere(pid,cid) values (@pid,@cid)"; IDbDataParameter paramPid = comm.CreateParameter(); paramPid.ParameterName = "@pid"; paramPid.Value = entity.Participant.Id; comm.Parameters.Add(paramPid); IDbDataParameter paramCid = comm.CreateParameter(); paramCid.ParameterName = "@cid"; paramCid.Value = entity.Cursa.Id; comm.Parameters.Add(paramCid); var result = comm.ExecuteNonQuery(); if (result == 0) { log.InfoFormat("save exited with value {0}", null); return(null); } else { log.InfoFormat("save exited with value {0}", result); return(entity); } } }
public Inscriere FindOne(KeyValuePair <int, int> id) { IDbConnection connection = DBUtils.getConnection(props); using (var command = connection.CreateCommand()) { command.CommandText = "select * from Inscrieri where idParticipant=@idParticipant and idProba=@idProba"; IDbDataParameter paramIdParticipant = command.CreateParameter(); paramIdParticipant.ParameterName = "@idParcitipant"; paramIdParticipant.Value = id.Key; command.Parameters.Add(paramIdParticipant); IDbDataParameter paramIdProba = command.CreateParameter(); paramIdProba.ParameterName = "@idProba"; paramIdProba.Value = id.Value; command.Parameters.Add(paramIdProba); using (var dataReader = command.ExecuteReader()) { if (dataReader.Read()) { int idParticipant = dataReader.GetInt32(0); int idProba = dataReader.GetInt32(1); Inscriere inscriere = new Inscriere(new KeyValuePair <int, int>(idParticipant, idProba)); return(inscriere); } } } return(null); }
public void save(Inscriere entity) { logger.InfoFormat("Se salveaza Inscrierea cu id-il {0}", entity.Id); IDbConnection conn = DBUtils.getConnection(); using (var com = conn.CreateCommand()) { com.CommandText = "insert into Inscriere values (@idInscriere,@idParticipant,@idCursa)"; IDbDataParameter paramIdAngajat = com.CreateParameter(); paramIdAngajat.ParameterName = "@idInscriere"; paramIdAngajat.Value = entity.Id; com.Parameters.Add(paramIdAngajat); IDbDataParameter paramidPart = com.CreateParameter(); paramidPart.ParameterName = "@idParticipant"; paramidPart.Value = entity.IdPart; com.Parameters.Add(paramidPart); IDbDataParameter paramidCursa = com.CreateParameter(); paramidCursa.ParameterName = "@idCursa"; paramidCursa.Value = entity.IdCursa; com.Parameters.Add(paramidCursa); var result = com.ExecuteNonQuery(); if (result == 0) { logger.Info("Error while adding"); throw new Exception("Nici o inscriere adaugata!"); } } logger.InfoFormat("A fost adaugat inscrierea cu id-ul {0}", entity.Id); }
//int id, Cursa c,Participant p public IEnumerable <Inscriere> findAll() { IDbConnection con = DBUtils.getConnection(); IList <Inscriere> inscrieri = new List <Inscriere>(); using (var comm = con.CreateCommand()) { comm.CommandText = "select id, idCursa, idParticipant from Inscrieri"; using (var dataR = comm.ExecuteReader()) { while (dataR.Read()) { int id = dataR.GetInt32(0); int idCursa = dataR.GetInt32(1); int idParticipant = dataR.GetInt32(2); Participant p = participantDb.findOne(idParticipant); Cursa c = cursaDb.findOne(idCursa); Inscriere inscriere = new Inscriere(id, c, p); inscrieri.Add(inscriere); } } } return(inscrieri); }
public void InscriereAdd(int iid, Participant p, Cursa c) { Inscriere i = new Inscriere(p, c); i.Id = iid; if (idr.Save(i) == null) { throw new Exception("Exista deja o inscriere cu acest id!"); } }
public void InscrieParticipant(string nume, int varsta, IList <ProbaDTO> probe) { //nume = nume + " " + prenume; int id = participantRepository.LastId(); Participant participant = new Participant(id, nume, varsta); participantRepository.Save(participant); foreach (var dto in probe) { Inscriere inscriere = new Inscriere(new KeyValuePair <int, int>(id, dto.Proba.ID)); inscriereRepository.Save(inscriere); } NotifyAll(); }
public void InscrirereParticipant(int capacitate, String numeParticipant, String numeEchipa) { int idCursa, idParticipant, idEchipa, idInscriere; idCursa = this.curse.findIdByCapacitate(capacitate); idEchipa = this.echipe.FindIdByName(numeEchipa); idParticipant = this.participanti.FindMaxId() + 1; idInscriere = this.inscrieri.FindMaxId() + 1; Participant nou = new Participant(idParticipant, numeParticipant, idEchipa); this.AddParticipant(nou); Inscriere noua = new Inscriere(idInscriere, idParticipant, idCursa); this.AddInscriere(noua); }
public async Task <IActionResult> OnGetAsync(int?id) { if (id == null) { return(NotFound()); } Inscriere = await _context.Inscrieri .Include(i => i.Curs) .Include(i => i.Student).AsNoTracking().FirstOrDefaultAsync(m => m.InscriereID == id); if (Inscriere == null) { return(NotFound()); } return(Page()); }
public async Task <IActionResult> OnPostAsync(int?id) { if (id == null) { return(NotFound()); } Inscriere = await _context.Inscrieri.FindAsync(id); if (Inscriere != null) { _context.Inscrieri.Remove(Inscriere); await _context.SaveChangesAsync(); } return(RedirectToPage("./Index")); }
public Inscriere addInscriere(string nume, int varsta, int idProba) { Participant p = findParticipant(nume, varsta); Inscriere inscriere = new Inscriere(_inscriereDbRepository.findAll().Count() + 1, p.IdParticipant, idProba); if (findInscriere(p.IdParticipant, idProba) != null) { return(null); } _inscriereDbRepository.save(inscriere); foreach (Proba proba in _probaDbRepository.findAll()) { if (proba.IdProba == idProba) { _probaDbRepository.update(idProba, new Proba(idProba, proba.Lungime, proba.Stil, proba.NrParticipanti + 1)); } } return(inscriere); }
public async Task <IActionResult> OnGetAsync(int?id) { if (id == null) { return(NotFound()); } Inscriere = await _context.Inscrieri .Include(i => i.Curs) .Include(i => i.Student).FirstOrDefaultAsync(m => m.InscriereID == id); if (Inscriere == null) { return(NotFound()); } ViewData["CursID"] = new SelectList(_context.Cursuri, "CursID", "CursID"); ViewData["StudentID"] = new SelectList(_context.Studenti, "ID", "ID"); return(Page()); }
private void inscrieButton_Click(object sender, EventArgs e) { try { int idCursa = Int32.Parse(idTextBox.Text); string nume = numeTextBox.Text; string echipa = echipaTextBox.Text; int capacMotor = Int32.Parse(categorieComboBox.SelectedItem.ToString()); Participant p = service.findParticipantByNumeSiEchipaSiCapacMotor(capacMotor, nume, echipa); Console.WriteLine(p.ToString()); Cursa c = service.findCursaByCapacMotor(capacMotor); Console.WriteLine(c.ToString()); c.Id = idCursa; Inscriere inscriere = new Inscriere(c, p); if (c.CapacMotor == capacMotor) { inscriereDbRepository.save(inscriere); cursaDbRepository.delete(idCursa); //sterg ca sa pot adauga noua cursa cu nrpers updatat c.NrPers = c.NrPers + 1; cursaDbRepository.save(c); //curseDataGridView.DataSource = service.findByCapacMotor(Int32.Parse(categorieComboBox.SelectedItem.ToString())); curseDataGridView.DataSource = service.getAllCurse(); } else { MessageBox.Show("Capacitatea motorului != categoria cursei"); } } catch (NullReferenceException ex) { MessageBox.Show("Selectati atat participantul cat si cursa pentru inscriere"); } catch (Exception ex) { MessageBox.Show("Participantul este deja inscris la cursa"); } }
public void Save(Inscriere entity) { IDbConnection connection = DBUtils.getConnection(props); using (var command = connection.CreateCommand()) { command.CommandText = "insert into Inscrieri values (@idParticipant, @idProba)"; IDbDataParameter paramIdParticipant = command.CreateParameter(); paramIdParticipant.ParameterName = "@idParticipant"; paramIdParticipant.Value = entity.ID.Key; command.Parameters.Add(paramIdParticipant); IDbDataParameter paramIdProba = command.CreateParameter(); paramIdProba.ParameterName = "@idProba"; paramIdProba.Value = entity.ID.Value; command.Parameters.Add(paramIdProba); command.ExecuteNonQuery(); } }
public IEnumerable <Inscriere> FindAll() { IDbConnection connection = DBUtils.getConnection(props); IList <Inscriere> list = new List <Inscriere>(); using (var command = connection.CreateCommand()) { command.CommandText = "select * from Inscrieri"; using (var dataReader = command.ExecuteReader()) { while (dataReader.Read()) { int idParticipant = dataReader.GetInt32(0); int idProba = dataReader.GetInt32(1); Inscriere inscriere = new Inscriere(new KeyValuePair <int, int>(idParticipant, idProba)); list.Add(inscriere); } } } return(list); }
public static void Initialize(SchoolContext context) { context.Database.EnsureCreated(); // Look for any Studenti. if (context.Studenti.Any()) { return; // DB has been seeded } var studenti = new Student[] { new Student { Nume = "Carson", Prenume = "Alexander", DataInscrierii = DateTime.Parse("2020-09-01") }, new Student { Nume = "Meredith", Prenume = "Alonso", DataInscrierii = DateTime.Parse("2018-09-01") }, new Student { Nume = "Arturo", Prenume = "Anand", DataInscrierii = DateTime.Parse("2019-09-01") }, new Student { Nume = "Gytis", Prenume = "Barzdukas", DataInscrierii = DateTime.Parse("2018-09-01") }, new Student { Nume = "Yan", Prenume = "Li", DataInscrierii = DateTime.Parse("2019-09-01") }, new Student { Nume = "Peggy", Prenume = "Justice", DataInscrierii = DateTime.Parse("2017-09-01") }, new Student { Nume = "Laura", Prenume = "Norman", DataInscrierii = DateTime.Parse("2019-09-01") }, new Student { Nume = "Nino", Prenume = "Olivetto", DataInscrierii = DateTime.Parse("2020-09-01") } }; context.Studenti.AddRange(studenti); context.SaveChanges(); var cursuri = new Curs[] { new Curs { CursID = 1050, Titlu = "Algoritmi si Structuri de Date", Credite = 3 }, new Curs { CursID = 4022, Titlu = "Baze De Date", Credite = 3 }, new Curs { CursID = 4041, Titlu = "Macroeconomie", Credite = 3 }, new Curs { CursID = 1045, Titlu = "Finante Publice", Credite = 4 }, new Curs { CursID = 3141, Titlu = "Medii de programare", Credite = 4 }, new Curs { CursID = 2021, Titlu = "Inteligenta Artificiala", Credite = 3 }, new Curs { CursID = 2042, Titlu = "Etica in Afaceri", Credite = 4 } }; context.Cursuri.AddRange(cursuri); context.SaveChanges(); var inscrieri = new Inscriere[] { new Inscriere { StudentID = 1, CursID = 1050, Nota = Nota.Nota_10 }, new Inscriere { StudentID = 1, CursID = 4022, Nota = Nota.Nota_7 }, new Inscriere { StudentID = 1, CursID = 4041, Nota = Nota.Nota_6 }, new Inscriere { StudentID = 2, CursID = 1045, Nota = Nota.Nota_2 }, new Inscriere { StudentID = 2, CursID = 3141, Nota = Nota.Nota_10 }, new Inscriere { StudentID = 2, CursID = 2021, Nota = Nota.Nota_3 }, new Inscriere { StudentID = 3, CursID = 1050 }, new Inscriere { StudentID = 4, CursID = 1050 }, new Inscriere { StudentID = 4, CursID = 4022, Nota = Nota.Nota_8 }, new Inscriere { StudentID = 5, CursID = 4041, Nota = Nota.Nota_7 }, new Inscriere { StudentID = 6, CursID = 1045 }, new Inscriere { StudentID = 7, CursID = 3141, Nota = Nota.Nota_10 }, }; context.Inscrieri.AddRange(inscrieri); context.SaveChanges(); }
public void AddInscriere(Inscriere inscriere) { this.inscrieri.save(inscriere); }