public IActionResult Update(StudentUpdate studentUpdate) { if (studentUpdate == null) { return(RedirectToActionPermanent("Index")); } if (!ModelState.IsValid) { return(View("Update", studentUpdate)); } using (var db = new SchoolContext()) { var student = db.Students.SingleOrDefault(s => s.Id == studentUpdate.Id); if (student == null) { return(RedirectToActionPermanent("Index")); } student.Firstname = studentUpdate.Firstname; student.Lastname = studentUpdate.Lastname; db.Students.Update(student); db.SaveChanges(); return(RedirectToActionPermanent("Index")); } }
public async Task <StudentUpdate> UpdateBasic(int studentId, StudentUpdate model) { var student = await context.Student.FirstOrDefaultAsync(_ => _.Id == studentId); if (student == null) { throw new ValidationException("Requested student doesn't exist."); } student.Firstname = model.Firstname; student.Lastname = model.Lastname; student.Jmbag = model.Jmbag; student.IndexNmb = model.IndexNmb; var errors = student.Validate(); if (errors.Any()) { throw new ValidationPropertyException(errors); } await context.SaveChangesAsync(); return(new StudentUpdate { Id = student.Id, Firstname = student.Firstname, Lastname = student.Lastname, Jmbag = student.Jmbag, IndexNmb = student.IndexNmb }); }
private void dgvStudents_CellClick(object sender, DataGridViewCellEventArgs e) { int columnIndex = e.ColumnIndex; int rowIndex = e.RowIndex; DataGridViewRow row = dgvStudents.Rows[rowIndex]; int studentID = Convert.ToInt32(row.Cells["colID"].Value.ToString()); Student student = students.FirstOrDefault(s => s.ID == studentID); switch (columnIndex) { case 5: StudentUpdate updateView = new StudentUpdate(_studentViewModel, student); updateView.ShowDialog(); if (updateView.Success) { LoadData(); } break; case 6: StudentDelete deleteView = new StudentDelete(_studentViewModel, student); deleteView.ShowDialog(); if (deleteView.Success) { LoadData(); } break; default: break; } }
public async Task RunAsync(CancellationToken stopToken) { Random random = new Random(); while (!stopToken.IsCancellationRequested) { int i = (int)(random.NextDouble() * Students.Count); if (i < Students.Count) { var student = Students[i]; var score = (student.Grades.First().Score = random.Next(50, 100));; var grade = student.Grades.First(); grade.Score = score; student.Age = random.Next(10, 35); student.Name = student.Name; student.Grades = new List <Grade> { grade }; StudentUpdate?.Invoke(this, student); } await Task.Delay(500, stopToken); } }
public void UpdateStudent(StudentUpdate studentUpdate) { var student = this.GetStudentById(studentUpdate.Id); this.mapper.Map(studentUpdate, student); context.SaveChanges(); }
public IActionResult Update(StudentUpdate student) { if (ModelState.IsValid) { studentService.Update(student); return(RedirectToAction("Index")); } return(View(student)); }
public async Task UpdateStudent([FromRoute] int id, [FromBody] StudentUpdate data) { var student = await _context.Students .FirstOrDefaultAsync(it => it.ID == id); if (student == null) { throw new ProblemDetailsException(ProblemDetailsFactory.CreateProblemDetails(this.HttpContext, 404)); } data.AdaptTo(student); await _context.SaveChangesAsync(); }
public async Task Updates_the_user_with_a_note() { var group = Fixture.DataMother.CreateGroup(studentNames: new[] { "TimO" }); var student = group.Students.FirstOrDefault(); await using var dbContext = Fixture.CreateDbContext(); var useCase = new StudentUpdate(dbContext); var result = await useCase.HandleAsync(new StudentUpdate.Command { Id = student !.Id, Name = "Timo", Note = "Everything is going just fine" });
public IHttpActionResult UpdateStudent(StudentUpdate student) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (!CreateStudentService().UpdateStudent(student)) { return(InternalServerError()); } return(Ok("Student updated")); }
public async Task UpdateStudentThroughRequestModelAsync(Student student, StudentUpdate studentUpdate) { student.FirstName = studentUpdate.FirstName; student.LastName = studentUpdate.LastName; student.Campus = studentUpdate.Campus; student.Description = studentUpdate.Description; student.LinkedInLink = studentUpdate.LinkedInLink; student.PortfolioLink = studentUpdate.PortfolioLink; student.Picture = studentUpdate.Picture; student.Role = studentUpdate.Role; await AddStudentSkillsAsync(studentUpdate.Skills, student); await UpdateAsync(student); }
public static StudentUpdateableModel MapStudentUpdateableModel(StudentUpdate source) { return(new StudentUpdateableModel { Student = new StudentUpdate { Id = source.Id, Firstname = source.Firstname, IndexNmb = source.IndexNmb, Jmbag = source.Jmbag, Lastname = source.Lastname } }); }
public async Task Delete(StudentUpdate student) { ValidationErrors = null; try { await _studentService.Delete(student.Id); Students.RowEditOptions.EditRowId = null; Students.RequestRefresh(); } catch (ValidationException ve) { ValidationErrors = ve.Errors; } }
public StudentUpdate GetStudentById(int id) { StudentUpdate student = new StudentUpdate(); using (IDbConnection con = new SqlConnection(strConnectionString)) { if (con.State == ConnectionState.Closed) { con.Open(); } DynamicParameters parameter = new DynamicParameters(); parameter.Add("@Id", id); student = con.Query <StudentUpdate>("Student_GetById", parameter, commandType: CommandType.StoredProcedure).FirstOrDefault(); } return(student); }
// Update specific item public StudentUpdate UpdateStudent(StudentUpdate updatedStudent) { var p = ds.Students.Find(updatedStudent.Id); if (p == null) { return(null); } else { // For the object fetched from the data store, // set its values to those provided // (the method ignores missing properties, and navigation properties) ds.Entry(p).CurrentValues.SetValues(updatedStudent); ds.SaveChanges(); return(updatedStudent); } }
public bool UpdateStudent(StudentUpdate model) { if (model is null) { return(false); } using (var ctx = new ApplicationDbContext()) { ApplicationUser student = ctx.Users.FirstOrDefault(x => x.StudentId == model.StudentId); student.First = model.FirstName; student.Last = model.LastName; student.Year = model.Year; student.Major = model.Major; return(ctx.SaveChanges() >= 1); } }
public async Task SaveEdit(StudentUpdate student) { ValidationErrors = null; try { await _studentService.UpdateBasic(student.Id, student); Students.RowEditOptions.EditRowId = null; Students.RequestRefresh(); } catch (ValidationPropertyException vpe) { ValidationErrors = vpe.ErrorsList; } catch (ValidationException ve) { ValidationErrors = ve.Errors; } }
public int Update(StudentUpdate student) { int rowAffected = 0; using (IDbConnection con = new SqlConnection(strConnectionString)) { if (con.State == ConnectionState.Closed) { con.Open(); } DynamicParameters parameters = new DynamicParameters(); parameters.Add("@Id", student.ID); parameters.Add("@Name", student.Name); parameters.Add("@DOB", student.DOB); parameters.Add("@Gender", student.Gender); parameters.Add("@Email", student.Email); parameters.Add("@LevelID", student.LevelID); parameters.Add("@LanguageID", student.LanguageID); rowAffected = con.Execute("Student_Update", parameters, commandType: CommandType.StoredProcedure); } return(rowAffected); }
public async Task <IActionResult> UpdateStudent([FromBody][Required] StudentUpdate student, [FromRoute] int studentId) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (!User.IsInRole("Admin")) { if (User.Identity.Name != studentId.ToString()) { return(BadRequest("Action not allowed")); } } Student result = await _studentService.GetByIdAsync(studentId); if (result != null) { await _studentService.UpdateStudentThroughRequestModelAsync(result, student); return(Ok()); } return(BadRequest("Student not found")); }
public void Update(StudentUpdate studentUpdate) { studentService.UpdateStudent(studentUpdate); }
public StudentUpdateableModel() { Student = new StudentUpdate(); }
public StudentController(ProgressContext context) { _context = context; _useCase = new StudentUpdate(context); }
public static StudentUpdateableModel MapStudentUpdateableModel(this StudentUpdateableModel dest, StudentUpdate source) { dest.Student.Id = source.Id; dest.Student.Firstname = source.Firstname; dest.Student.IndexNmb = source.IndexNmb; dest.Student.Jmbag = source.Jmbag; dest.Student.Lastname = source.Lastname; return(dest); }
public void UpdateStudent(StudentUpdate studentUpdate) { studentRepository.UpdateStudent(studentUpdate); }
public void Edit(StudentUpdate student) { Students.RowEditOptions.EditRowId = student.Id; }