public IHttpActionResult CapNhatSV(CapNhatSinhVien model) { IHttpActionResult httpActionResult; ErrorModel errors = new ErrorModel(); TTSV sv = this.db.TTSVs.FirstOrDefault(x => x.Id == model.Id); if (sv == null) { errors.Add("Không tìm thấy lớp"); // httpActionResult = Ok(errors); httpActionResult = new ErrorActionResult(Request, System.Net.HttpStatusCode.NotFound, errors); } else { sv.MaSv = model.MaSv ?? model.MaSv; sv.NgaySinh = model.NgaySinh; sv.HoTen = model.HoTen ?? model.HoTen; this.db.Entry(sv).State = System.Data.Entity.EntityState.Modified; this.db.SaveChanges(); httpActionResult = Ok(new SinhVien_model(sv)); } return(httpActionResult); }
public IHttpActionResult TaoSV(TaoSinhVien model) { IHttpActionResult httpActionResult; ErrorModel errors = new ErrorModel(); if (string.IsNullOrEmpty(model.MaSv)) { errors.Add("Mã sinh vien là trường bắt buộc"); } if (errors.Errors.Count == 0) { TTSV sv = new TTSV(); sv.MaSv = model.MaSv; sv.HoTen = model.HoTen; sv.NgaySinh = model.NgaySinh; sv.lop = db.TTLOPs.FirstOrDefault(x => x.Id == model.LopId); sv = db.TTSVs.Add(sv); this.db.SaveChanges(); SinhVien_model SV = new SinhVien_model(sv); httpActionResult = Ok(SV); } else { // httpActionResult = Ok(errors); httpActionResult = new ErrorActionResult(Request, System.Net.HttpStatusCode.BadRequest, errors); } return(httpActionResult); }
private void btnAdd_Click(object sender, EventArgs e) { TTSV fTT = new TTSV(null); fTT.ShowDialog(); Show(0, txbSearch.Text); }
public SinhVien_model(TTSV ttsv) { this.Id = ttsv.Id; this.MaSv = ttsv.MaSv; this.HoTen = ttsv.HoTen; this.NgaySinh = ttsv.NgaySinh; this.LopId = ttsv.lop.Id; }
private void btnEdit_Click(object sender, EventArgs e) { DataGridViewSelectedRowCollection data = dtgSV.SelectedRows; if (data.Count == 1) { string MSSV = data[0].Cells["MSSV"].Value.ToString(); //Form2 fTT = new Form2(MSSV); //fTT.ShowDialog(); //Show(0, txbSearch.Text); TTSV fTT = new TTSV(MSSV); fTT.ShowDialog(); Show(0, txbSearch.Text); } }