public IHttpActionResult Update([FromBody] StudentsResponseModel model) { if (!this.ModelState.IsValid) { return(this.BadRequest(this.ModelState)); } var student = this.data.Students .SearchFor(s => s.StudentIdentification == model.StudentIdentification) .FirstOrDefault(); if (student == null) { return(this.NotFound()); } student.Level = model.Level; // moje da se e ojenil, kazva bobi student.LastName = model.LastName; this.data.Students.Update(student); this.data.SaveChanges(); return(this.Ok(student)); }
public IHttpActionResult Post([FromBody] StudentsResponseModel model) { if (!this.ModelState.IsValid) { return(this.BadRequest(this.ModelState)); } var student = this.models.Get <Student>(model); this.data.Students.Add(student); this.data.SaveChanges(); return(this.Created(this.Url.ToString(), student)); }
public IHttpActionResult Remove([FromBody] StudentsResponseModel model) { var studentToRemove = this.data.Students .SearchFor(s => s.FirstName == model.FirstName && s.LastName == model.LastName) .FirstOrDefault(); if (studentToRemove == null) { return(this.NotFound()); } this.data.Students.Delete(studentToRemove); this.data.SaveChanges(); return(this.Ok(studentToRemove)); }