public IActionResult Insert([FromBody] WorkingHoursDomain workingHours) { try { var data = _workingHoursRepository.Insert(workingHours); return(Ok()); } catch (Exception ex) { return(new StatusCodeResult(500)); } }
private bool searchForWorkHour(WorkingHoursDomain workingHours) { using var connection = new SqlConnection(_connectionString); var workingHoursResult = connection.Query <WorkingHoursDomain>("SELECT * " + "FROM TBL_WORKING_HOURS " + $"WHERE DATE_END >= '{workingHours.DateInit}' AND ID_DEVELOPER = {workingHours.IdDeveloper}"); connection.Close(); if (workingHoursResult.Any()) { return(true); } return(false); }
public int Insert(WorkingHoursDomain workingHours) { bool found = searchForWorkHour(workingHours); if (found) { throw new Exception("Work hour already registered in data base."); } using var connection = new SqlConnection(_connectionString); var query = "insert into tbl_working_hours (date_init, date_end, id_developer) " + $"values ('{workingHours.DateInit}', '{workingHours.DateEnd}', {workingHours.IdDeveloper})"; var result = connection.Execute(query); connection.Close(); return(result); }