public async Task <IActionResult> PutOpenSeats([FromBody] Model.OpenSeats OpenSeats) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } //Check if this record exists already //if it does, return if (OpenSeatsExists(OpenSeats)) { return(NoContent()); } //if it doesnt, add it else { _dbContext.OpenSeats.Add(OpenSeats); } try { await _dbContext.SaveChangesAsync(); } catch (Exception) { throw; } return(NoContent()); }
private bool OpenSeatsExists(Model.OpenSeats seats) { return(_dbContext.OpenSeats.Any(c => (c.Date.Date == seats.Date.Date && c.EmployeeId.ToUpper() == seats.EmployeeId.ToUpper()))); }