public IHttpActionResult PostCheckIn([FromBody] CheckInDTO checkIn) { if (!ModelState.IsValid) { return BadRequest(ModelState); } // Validate event pin var e = db.Events.FirstOrDefault(x => x.Id == checkIn.EventId); if (e.Pin != null) { if (e.Pin != checkIn.Pin) { return BadRequest("Invalid pin. Please check your entries and try again."); } } // Make sure this user hasn't already checked in var existing = db.CheckIns.FirstOrDefault(x => x.EventId == checkIn.EventId && x.StudentIdentifier == checkIn.StudentId); if (existing != null) { return BadRequest("You have already checked in to this event."); } var c = new CheckIn { CreateDate = DateTime.Now, EventId = checkIn.EventId, StudentIdentifier = checkIn.StudentId }; db.CheckIns.Add(c); db.SaveChanges(); return CreatedAtRoute("DefaultApi", new { id = c.CheckInId }, c); }
public IHttpActionResult PutCheckIn(int id, CheckIn checkIn) { if (!ModelState.IsValid) { return BadRequest(ModelState); } if (id != checkIn.CheckInId) { return BadRequest(); } db.Entry(checkIn).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!CheckInExists(id)) { return NotFound(); } else { throw; } } return StatusCode(HttpStatusCode.NoContent); }