public IActionResult ModifyStudent(string index, ModifyStudentRequest req) { var context = new uniContext(); var changed = from Student s in context.Student where s.Indexnumber == index select s; foreach (Student s in changed) { if (req.Firstname != null) { s.Firstname = req.Firstname; } if (req.Lastname != null) { s.Lastname = req.Lastname; } if (req.Birthdate != null) { try { var newDate = DateTime.ParseExact(req.Birthdate, "dd.MM.yyyy", CultureInfo.InvariantCulture); s.Birthdate = newDate; } catch (Exception e) { return(BadRequest("Incorrect date format. Correct format: dd.MM.yyyy")); } } } context.SaveChanges(); return(Created("api/students/" + index, changed.First())); }
public ModifyStudentResponse ModifyStudent(string index, ModifyStudentRequest request) { var db = new s18985Context(); var s = db.Student.Where(d => d.IndexNumber == index).FirstOrDefault(); if (s == null) { return(null); } else { s.FirstName = request.FirstName; s.LastName = request.LastName; s.BirthDate = request.BirthDate; db.SaveChanges(); ModifyStudentResponse response = new ModifyStudentResponse(); response.IndexNumber = s.IndexNumber; response.FirstName = s.FirstName; response.LastName = s.LastName; response.BirthDate = s.BirthDate; return(response); } }
public void ModifyStudent(ModifyStudentRequest modifyStudentRequest) { _context.Students.Where(s => s.IdStudent == modifyStudentRequest.IdStudent).ToList().ForEach(s => { s.FirstName = modifyStudentRequest.FirstName; s.LastName = modifyStudentRequest.LastName; }); }
public void ModifyStudent(ModifyStudentRequest request) { var student = _context.Student.Find(request.IndexNumber); student.FirstName = request.FirstName; student.LastName = request.LastName; student.BirthDate = request.BirthDate; _context.SaveChanges(); }
public IActionResult ModifyStudent(ModifyStudentRequest request) { try { Student student = _service.ModifyStudent(request); return(Ok(student)); } catch (Exception e) { return(BadRequest(e.Message)); } }
public IActionResult ModifyStudent(ModifyStudentRequest request) { try { var student = _service.ModifyStudent(request); return(Created("ModifyStudent", student)); } catch (Exception e) { return(BadRequest(e.Message)); } }
public async Task <IActionResult> UpdateStudentAsync(ModifyStudentRequest msr) { int i = 0; i = await _db.ModifyStudentAsync(msr); if (i == -1) { return(NotFound("Student does not exist")); } return(Ok("Student updated")); }
public IActionResult ModifyStudent(string index, ModifyStudentRequest request) { var res = _service.ModifyStudent(index, request); if (res != null) { return(Ok(res)); } else { return(NotFound("Nie ma takiego studenta")); } }
[Route("api/students/modifyStudent")] //zmień na student public IActionResult ModifyStudent(ModifyStudentRequest request) { var db = new _2019SBDContext(); var s = new Student { IndexNumber = request.IndexNumber, FirstName = request.FirstName, LastName = request.LastName, BirthDate = request.BirthDate }; db.Attach(s); if (request.FirstName != null) { db.Entry(s).Property("FirstName").IsModified = true; } if (request.LastName != null) { db.Entry(s).Property("LastName").IsModified = true; } if (request.BirthDate != null) { db.Entry(s).Property("BirthDate").IsModified = true; } db.SaveChanges(); var db2 = new _2019SBDContext(); var res = db2.Student .Where(d => d.IndexNumber == request.IndexNumber) .FirstOrDefault(); var response = new ModifyStudentResponse(); response.IndexNumber = res.IndexNumber; response.FirstName = res.FirstName; response.LastName = res.LastName; response.BirthDate = res.BirthDate; return(Ok(response)); }
public Student ModifyStudent(ModifyStudentRequest request) { var student = _context.Student.Find(request.IndexNumber); if (student == null) { throw new Exception("no such student"); } student.FirstName = request.FirstName; student.LastName = request.LastName; student.BirthDate = request.Birthdate; _context.SaveChanges(); return(student); }
public IActionResult ModifyStudent(ModifyStudentRequest request) { ModifyStudentResponse response; try { response = _dbService.ModifyStudent(request); } catch (Exception ex) { return(BadRequest("Something went wrong")); } return(Ok(response)); }
public IActionResult ModifyStudent(ModifyStudentRequest request) { IActionResult response = Ok($"Successfully modified {request.IndexNumber}"); try { _dbService.ModifyStudent(request); } catch (Exception e) { response = BadRequest(e); } return(response); }
public void ModifyStudent(ModifyStudentRequest request) { var st = new Student { IndexNumber = request.IndexNumber, FirstName = request.FirstName, LastName = request.LastName, BirthDate = request.BirthDate, IdEnrollment = request.IdEnrollment, }; _dbContext.Attach(st); _dbContext.Entry(st).State = EntityState.Modified; _dbContext.SaveChanges(); }
[Route("api/students/deleteStudent")] //zmień na student public IActionResult DeleteStudent(ModifyStudentRequest request) { var db = new _2019SBDContext(); var student = new Student { IndexNumber = request.IndexNumber }; db.Attach(student); db.Remove(student); db.SaveChanges(); return(Ok(request.IndexNumber + " zostal usunięty")); }
public void ModifyStudent(ModifyStudentRequest request) { var s = new Student { IndexNumber = request.indexNumber, FirstName = request.firstName, LastName = request.lastName, BirthDate = request.birthDate, IdEnrollment = request.idEnrollment, Password = request.password }; _dbContext.Attach(s); _dbContext.Entry(s).State = EntityState.Modified; _dbContext.SaveChanges(); }
public IActionResult ModifyStudent(ModifyStudentRequest request) { IActionResult response; try { _context.ModifyStudent(request); response = Ok("Pomyslnie zmodyfikowano studenta o indexie " + request.indexNumber); } catch (Exception exc) { response = BadRequest("Błąd przy modyfikowaniu studenta" + exc.StackTrace); } return(response); }
public async Task <IActionResult> ModifyStudent(ModifyStudentRequest request) { var student = _context.Student.FirstOrDefault(n => n.IndexNumber == request.IndexNumber); if (student == null) { return(new BadRequestResult()); } student.FirstName = request.FirstName; student.LastName = request.LastName; student.BirthDate = request.BirthDate; student.IdEnrollment = request.IdEnrollment; await _context.SaveChangesAsync(); return(new OkObjectResult(student)); }
public void ModifyStudent(ModifyStudentRequest request) { try { var student = (from s in _context.Student where s.IndexNumber == request.IndexNumber select s).Single(); student.FirstName = request?.FirstName ?? student.FirstName; student.LastName = request?.LastName ?? student.LastName; student.BirthDate = request?.BirthDate ?? student.BirthDate; student.IdEnrollment = request?.IdEnrollment ?? student.IdEnrollment; _context.SaveChanges(); } catch (Exception e) { throw new Exception( $"Couldn\'t update student {request.IndexNumber} due to: {e.StackTrace} {e.Message}" ); } }
public Student ModifyStudent(ModifyStudentRequest request) { var student = _context.Student.FirstOrDefault(e => e.IndexNumber == request.IndexNumber); if (student == null) { throw new Exception("Nie ma takiego studenta"); } student.IndexNumber = request.IndexNumber; student.FirstName = request.FirstName; student.LastName = request.LastName; student.BirthDate = request.BirthDate; student.IdEnrollment = request.IdEnrollment; _context.SaveChanges(); return(student); }
public ModifyStudentResponse ModifyStudent(ModifyStudentRequest request) { try { var student = _dbContext.Student.Where(s => s.IndexNumber == request.IndexNumber).Single(); student.FirstName = request?.FirstName ?? student.FirstName; student.LastName = request?.LastName ?? student.LastName; // student.IdEnrollment = request?.IdEnrollment ?? student.IdEnrollment; ------ Nie mozna zmienic bo klucz obcy i wyrzuca wyjatek student.BirthDate = request?.birthDate ?? student.BirthDate; student.Password = request?.password ?? student.Password; _dbContext.SaveChanges(); } catch (Exception exc) { throw exc; } /* var student = new Student * { * FirstName = request.FirstName, * LastName = request.LastName, * IndexNumber = request.LastName, * IdEnrollment = request.IdEnrollment, * BirthDate = request.birthDate, * Password = request.password * }; * _dbContext.Attach(student); * _dbContext.Entry(student).State = EntityState.Modified; * _dbContext.SaveChanges(); */ return(new ModifyStudentResponse { FirstName = request.FirstName, LastName = request.LastName, IndexNumber = request.LastName, IdEnrollment = request.IdEnrollment, birthDate = request.birthDate }); }
public async Task <int> ModifyStudentAsync(ModifyStudentRequest usr) { var exists = _studentContext.Student.Any(s => s.IndexNumber == usr.IndexNumber); if (!exists) { return(-1); } var st = new Student { IndexNumber = usr.IndexNumber, FirstName = usr.FirstName, LastName = usr.LastName, BirthDate = usr.BirthDate, IdEnrollment = usr.IdEnrollment, Password = usr.Password }; _studentContext.Attach(st); _studentContext.Entry(st).State = EntityState.Modified; await _studentContext.SaveChangesAsync(); return(0); }
public IActionResult ModifyStudent(ModifyStudentRequest request) { if (request == null || request.IndexNumber == null) { return(BadRequest("Brak danych wejściowych")); } var student = db.Student.Where(s => s.IndexNumber.Equals(request.IndexNumber)).ToList().First(); if (student == null) { return(NotFound("Student with index: @index not found")); } if (request.FirstName != null) { student.FirstName = request.FirstName; } if (request.LastName != null) { student.LastName = request.LastName; } if (request.BirthDate != null) { student.BirthDate = request.BirthDate; } if (request.IdEnrollment != 0) { student.IdEnrollment = request.IdEnrollment; } db.Student.Update(student); db.SaveChanges(); return(Ok()); }
public IActionResult ModifyStudent(ModifyStudentRequest modifyStudentRequest) { return Ok(_dbService.ModifyStudent(modifyStudentRequest)); }
public void ModifyStudent(ModifyStudentRequest request) { throw new NotImplementedException(); }
public IActionResult ModifyStudent(ModifyStudentRequest request) { _service.ModifyStudent(request); return(Ok("Student's data was successfully modified")); }
public async Task <IActionResult> ModifyStudent(ModifyStudentRequest request) { return(await _service.ModifyStudent(request)); }