public IHttpActionResult Update([FromUri] int id, [FromBody] UpdateStudentModel model) { //Init model if model null if (model == null) { model = new UpdateStudentModel(); Validate(model); } //Validate if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var student = DbSet.Students.Find(id); if (student != null) { student.Name = model.Name; student.Code = model.Code; student.ClassId = model.ClassId; DbSet.SaveChanges(); return(Ok()); } return(NotFound()); }
public async Task <IActionResult> UpdateStudent([FromBody] UpdateStudentModel updateStudentModel) { UpdateStudentDto updateStudentDto = _mapper.Map <UpdateStudentDto>(updateStudentModel); await _studentService.UpdateStudentAsync(updateStudentDto); return(Ok()); }
public IHttpActionResult Update(UpdateStudentModel model) { IHttpActionResult httpActionResult; ErrorsModel errors = new ErrorsModel(); Students sv = this._db.Students.FirstOrDefault(x => x.Id == model.Id); if (sv == null) { errors.Add("Không tìm thấy mã sinh viên này"); httpActionResult = new ErrorActionResult(Request, System.Net.HttpStatusCode.NotFound, errors); } else { sv.Code = model.Code ?? model.Code; sv.Name = model.Name ?? model.Name; sv.BirthDay = model.BirthDay ?? model.BirthDay; sv.Address = model.Address ?? model.Address; this._db.Entry(sv).State = System.Data.Entity.EntityState.Modified; this._db.SaveChanges(); httpActionResult = Ok(new StudentModel(sv)); } return(httpActionResult); }
public IHttpActionResult CapNhatSV(UpdateStudentModel model) { IHttpActionResult httpActionResult; ErrorModel errors = new ErrorModel(); Student sv = this._db.Students.FirstOrDefault(x => x.Id == model.Id); if (sv == null) { errors.Add("Không tìm th?y sv"); httpActionResult = Ok(errors); } else { sv.MSSV = model.MaSV ?? model.MaSV; sv.HoTen = model.HoTenSV ?? model.HoTenSV; sv.DiaChi = model.DiaChi ?? model.DiaChi; this._db.Entry(sv).State = System.Data.Entity.EntityState.Modified; this._db.SaveChanges(); httpActionResult = Ok(new StudentModel(sv)); } return(httpActionResult); }
public IHttpActionResult Update(UpdateStudentModel model) { IHttpActionResult httpActionResult; ErrorModel errors = new ErrorModel(); Student sv = this._db.Students.FirstOrDefault(x => x.Id == model.Id); if (sv == null) { errors.Add("Không tìm thấy Sinh viên"); httpActionResult = new ErrorActionResult(Request, System.Net.HttpStatusCode.NotFound, errors); } else { sv.HoTen = model.HoTen ?? model.HoTen; sv.MSSV = model.MSSV ?? model.MSSV; sv.NgaySinh = model.NgaySinh; sv.DiaChi = model.DiaChi ?? model.DiaChi; sv.Class = _db.Class.FirstOrDefault(m => m.Id == model.LOP_ID); this._db.Entry(sv).State = System.Data.Entity.EntityState.Modified; this._db.SaveChanges(); httpActionResult = Ok(new StudentModel(sv)); } return(httpActionResult); }
public StudentsControllerTests() { updateStudentModel = new UpdateStudentModel(); mockRepo = new Mock <IStudentService>(); mockRepoGrade = new Mock <IGradeService>(); controller = new StudentsController(mockRepo.Object, mockRepoGrade.Object); studentModel = Mapper.Map <UpdateStudentModel, Student>(updateStudentModel); }
public async Task <IActionResult> UpdateStudent([FromBody] UpdateStudentModel updateStudentModel, Guid id) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var studentModel = Mapper.Map <UpdateStudentModel, Student>(updateStudentModel); await this.studentService.UpdateAsync(id, studentModel); return(NoContent()); }
public async Task <JsonResult> UpdateStudent(UpdateStudentModel student) { if (student.StudentId == Guid.Empty) { return(Json(false, JsonRequestBehavior.AllowGet)); } var result = await _studentOrchestrator.UpdateStudent(new StudentViewModel { StudentId = student.StudentId, StudentName = student.StudentName, Height = student.Height, Weight = student.Weight }); return(Json(result, JsonRequestBehavior.AllowGet)); }
public IHttpActionResult UpdateStudent(UpdateStudentModel model) { IHttpActionResult httpActionResult; ErrorModel error = new ErrorModel(); Student sv = this._db.Student.FirstOrDefault(x => x.Id == model.Id); if (sv == null) { error.Add("Không tìm thấy Sinh viên!"); httpActionResult = new ErrorActionResult(Request, System.Net.HttpStatusCode.BadRequest, error); } else { sv.StudentName = model.StudentName ?? model.StudentName; sv.StudentId = model.StudentId; sv.StudentBirth = model.StudentBirth; sv.StudentAddress = model.StudentAddress ?? model.StudentAddress; //sv.Class.Id = model.ClassId; this._db.Entry(sv).State = System.Data.Entity.EntityState.Modified; this._db.SaveChanges(); httpActionResult = Ok(new StudentModel(sv)); } return(httpActionResult); }
public IActionResult UpdateStudent(UpdateStudentModel model) { model.Modify(); return(View(model)); //return RedirectToAction("Index"); }
public IActionResult UpdateStudent() { var model = new UpdateStudentModel(); return(View(model)); }