public Supliment Delete(Supliment Supliment) { var result = _context.Remove(Supliment); _context.SaveChanges(); return(result.Entity); }
public async Task <IActionResult> Edit(int id, [Bind("ID,Denumire,Cantitate,Price")] Supliment supliment) { if (id != supliment.ID) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(supliment); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!SuplimentExists(supliment.ID)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(supliment)); }
public Supliment Create(Supliment Supliment) { var result = _context.Add <Supliment>(Supliment); _context.SaveChanges(); return(result.Entity); }
public async Task <IActionResult> Create([Bind("ID,Denumire,Cantitate,Price")] Supliment supliment) { if (ModelState.IsValid) { _context.Add(supliment); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(supliment)); }
public Supliment Post(SuplimentDTO value) { Supliment model = new Supliment() { denumire = value.Denumire, pret = value.Pret, tip = value.Tip }; return(ISuplimentRepository.Create(model)); }
private void btnSave_Click(object sender, EventArgs e) { int UserId; Supliment sp2 = new Supliment(); List <int> subjectId = new List <int>(); for (int i = 0; i <= dgvUser.Rows.Count - 1; i++) { if (Convert.ToBoolean(dgvUser.Rows[i].Cells[0].Value) == true) { using (AppContext db = new AppContext()) { UserId = Convert.ToInt32(dgvUser.Rows[i].Cells[1].Value); UserDetails ud = (from x in db.Details select x).Where(x => x.Id == UserId && x.Deleted == false).SingleOrDefault(); Course cr = (from y in db.Courses select y).Where(y => y.Id == crsId && y.Deleted == false).SingleOrDefault(); Supliment sup = (from z in db.Supliments select z).Where(z => z.UserDetailsId == ud.Id && z.CourseId == cr.Id).FirstOrDefault(); //sp2.Ocupation = cr.Ocupation; //sp2.Furnizor = cr.OrganizedBy; //sp2.Hours = cr.Duration; sp2.CourseId = cr.Id; sp2.UserDetailsId = ud.Id; if (sup == null) { sp.Deleted = false; db.Entry(sp2).State = EntityState.Added; //ud.FullName = txtFirstName.Text.Trim() + " " + txtLastName.Text.Trim(); //MessageBox.Show("Added"); //sp2.Course = null; //sp2.Users = null; db.SaveChanges(); } else if (sup.Deleted == true) { sup.Deleted = false; db.Entry(sup).State = EntityState.Modified; //ud.FullName = txtFirstName.Text.Trim() + " " + txtLastName.Text.Trim(); //MessageBox.Show("Added"); //sp2.Course = null; //sp2.Users = null; db.SaveChanges(); } } } } }
public async Task <IActionResult> OnGetAsync(int?id) { if (id == null) { return(NotFound()); } Supliment = await _context.Supliment.FirstOrDefaultAsync(m => m.ID == id); if (Supliment == null) { return(NotFound()); } return(Page()); }
public async Task <IActionResult> OnPostAsync(int?id) { if (id == null) { return(NotFound()); } Supliment = await _context.Supliment.FindAsync(id); if (Supliment != null) { _context.Supliment.Remove(Supliment); await _context.SaveChangesAsync(); } return(RedirectToPage("./Index")); }
public Supliment Put(int id, SuplimentDTO value) { Supliment model = ISuplimentRepository.Get(id); if (value.Denumire != null) { model.denumire = value.Denumire; } if (value.Pret != 0) { model.pret = value.Pret; } if (value.Tip != null) { model.tip = value.Tip; } return(ISuplimentRepository.Update(model)); }
private void dgvDisplayUsers_CellClick(object sender, DataGridViewCellEventArgs e) { if (e.RowIndex == dgvDisplayUsers.NewRowIndex || e.RowIndex < 0) { return; } if (e.ColumnIndex == dgvDisplayUsers.Columns["Delete"].Index) { DataGridView dgv = sender as DataGridView; if (dgv == null) { return; } // cand apesi pe o celula ia tot randul atunci de-comenteaza if-ul //if (dgv.CurrentRow.Selected) //{ ud = (UserDetails)dgv.CurrentRow.DataBoundItem; //sa tinem minte id ul cursului using (AppContext db = new AppContext()) { Supliment sp = (from z in db.Supliments select z).Where(z => z.UserDetailsId == ud.Id && z.CourseId == cr.Id).FirstOrDefault(); var entry = db.Entry(sp); //if (entry.State == EntityState.Detached) // db.Supliments.Attach(sp); sp.Deleted = true; db.Entry(sp).State = EntityState.Modified; db.SaveChanges(); MessageBox.Show("Deleted Succesfully"); this.dgvDisplayUsers.DataSource = null; this.dgvDisplayUsers.Rows.Clear(); PopulateDataGridView(); } } }
private void frmSupliment_Load(object sender, EventArgs e) { using (AppContext db = new AppContext()) { Course cr = (from y in db.Courses select y).Where(y => y.Id == crsId && y.Deleted == false).SingleOrDefault(); Supliment sup = (from z in db.Supliments select z).Where(z => z.CourseId == cr.Id).FirstOrDefault(); txtType.Text = sup.Type; txtSeries.Text = sup.Seria; txtNumber.Text = sup.Number.ToString(); txtOcupation.Text = sup.Ocupation; txtCOR.Text = cr.COR.ToString(); txtOrganizedBy.Text = cr.OrganizedBy; txtCalifLevel.Text = sup.Califications; txtStudyLevel.Text = sup.StudyLevel; txtProgramType.Text = sup.ProgramType; txtHours.Text = sup.Hours.ToString(); txtTotal.Text = sup.Total.ToString(); txtTeoreticPreg.Text = sup.TeoreticPreg; txtPractPreg.Text = sup.PracticPreg; txtCompetences.Text = sup.Competences; } }
private void btnEdit_Click(object sender, EventArgs e) { using (AppContext db = new AppContext()) { Course cr = (from y in db.Courses select y).Where(y => y.Id == crsId && y.Deleted == false).SingleOrDefault(); Supliment sup = (from z in db.Supliments select z).Where(z => z.CourseId == cr.Id).FirstOrDefault(); sup.Type = txtType.Text.Trim(); sup.Seria = txtSeries.Text.Trim(); sup.Number = int.Parse(txtNumber.Text.Trim()); sup.Ocupation = cr.Ocupation; sup.Hours = cr.Duration; cr.COR = int.Parse(txtCOR.Text); cr.OrganizedBy = txtOrganizedBy.Text.Trim(); sup.Califications = txtCalifLevel.Text.Trim(); sup.StudyLevel = txtStudyLevel.Text.Trim(); sup.ProgramType = txtProgramType.Text.Trim(); sup.Total = int.Parse(txtTotal.Text.Trim()); sup.TeoreticPreg = txtTeoreticPreg.Text.Trim(); sup.PracticPreg = txtPractPreg.Text.Trim(); sup.Competences = txtCompetences.Text.Trim(); if (MessageBox.Show("Are you sure you want to edit this user?", "Operation", MessageBoxButtons.YesNo) == DialogResult.Yes) { if (crsId == sup.CourseId) { db.Entry(sup).State = EntityState.Modified; MessageBox.Show("Edited"); } else { db.Entry(sup).State = EntityState.Added; MessageBox.Show("Added"); } } db.SaveChanges(); } }
public Supliment Update(Supliment Supliment) { _context.Entry(Supliment).State = Microsoft.EntityFrameworkCore.EntityState.Modified; _context.SaveChanges(); return(Supliment); }
public Supliment Delete(int id) { Supliment model = ISuplimentRepository.Get(id); return(ISuplimentRepository.Delete(model)); }