//Students: public void EditStudent(EditStudentDTO dto) { var editStudent = Context.Users.FirstOrDefault(t => t.Id == dto.Id); editStudent.LastName = dto.LastName; editStudent.Name = dto.Name; editStudent.Age = dto.Age; editStudent.Email = dto.Email; Context.SaveChanges(); }
//[Authorize(Roles = "Admin")] public IActionResult EditStudent(EditStudentDTO dto) { if (!ModelState.IsValid) { return(BadRequest("Please, enter all field correct")); } else { CommandService.EditStudent(dto); return(Ok("The student has successfully edited")); } }
public async Task <StudentDTO> EditAsync(EditStudentDTO editStudent) { try { var entity = await _db.Students.FindAsync(editStudent.StudentId); entity.FirstName = string.IsNullOrEmpty(editStudent.FirstName) ? entity.FirstName : editStudent.FirstName; entity.LastName = string.IsNullOrEmpty(editStudent.LastName) ? entity.LastName : editStudent.FirstName; entity.AverageGrade = editStudent.AverageGrade.HasValue ? entity.AverageGrade : editStudent.AverageGrade.Value; entity.UniversityId = editStudent.UniversityId.HasValue ? entity.AverageGrade : editStudent.UniversityId.Value; await _db.SaveChangesAsync(); return(new StudentDTO { StudentId = entity.StudentId, FirstName = entity.FirstName, LastName = entity.LastName, AverageGrade = entity.AverageGrade }); } catch { return(null); } }