public async Task <IActionResult> AddOrUpdate(OvertimePostDto data) { if (data == null) { throw new ArgumentNullException(nameof(data)); } try { var result = await _service .AddOrUpdate( new Overtime { OvertimeId = data.OvertimeId, Date = data.Date, TypeName = data.TypeName, ClockNumber = data.ClockNumber, Comment = data.Comment, Hours = data.Hours, ModifiedDate = data.ModifiedDate } ) .ConfigureAwait(false); if (data.TypeName != "Mandatory") { return(Ok(result)); } const string voluntary = "Voluntary"; var overtimeId = await _service .GetOvertimeId( new Overtime { Date = data.Date, ClockNumber = data.ClockNumber, TypeName = voluntary } ) .ConfigureAwait(false); await _service .AddOrUpdate( new Overtime { OvertimeId = overtimeId, Date = data.Date, TypeName = voluntary, ClockNumber = data.ClockNumber, Comment = data.Comment, Hours = data.Hours, ModifiedDate = data.ModifiedDate } ) .ConfigureAwait(false); return(Ok(result)); } catch (Exception e) { return(BadRequest(e.Message)); } }