public IHttpActionResult PutNote(int id, Note note) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != note.Id) { return(BadRequest()); } db.Entry(note).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException ex) { if (!NoteExists(id)) { return(NotFound()); } else { throw ex; } } return(StatusCode(HttpStatusCode.NoContent)); }
public void SaveResponse(UserResponseModel userResponse) { try { using (YacEntities context = new YacEntities()) { var dbUserResponse = context.Set <UserResponse>(); dbUserResponse.Add(new UserResponse { IdUser = userResponse.IdUser, DateResponse = userResponse.DateResponse, Response = userResponse.Response }); context.SaveChanges(); } } catch (Exception ex) { throw new Exception(ex.Message); } }
public bool DeleteRegister(int idRegister) { try { using (YacEntities context = new YacEntities()) { var register = new UserResponse { Id = idRegister }; context.UserResponse.Attach(register); context.UserResponse.Remove(register); context.SaveChanges(); } return(true); } catch (Exception ex) { throw new Exception(ex.Message); } }