public IActionResult addTask(Requests.TaskRequest request) { try { _dbService.addTask(request); }catch (Exception e) { return(NotFound(e.GetBaseException())); } return(Ok()); }
public void addTask(Requests.TaskRequest request) { var connection = new SqlConnection("Data Source=db-mssql;Initial Catalog=s19541;Integrated Security=True"); connection.Open(); var transaction = connection.BeginTransaction("myTransaction"); if (!inTaskType(request.taskType.name)) { using (var com = new SqlCommand()) { com.Connection = connection; com.CommandText = "insert into TaskType values(@name)"; com.Parameters.AddWithValue("name", request.taskType.name); com.Transaction = transaction; com.ExecuteNonQuery(); } } using (var com = new SqlCommand()) { com.Connection = connection; com.CommandText = "insert into Task values(@name,@description,@deadLine,@idProject,(select IdTaskType from taskType where Name=@taskTypeName),@idAssignedTo,@idCreator)"; com.Parameters.AddWithValue("name", request.name); com.Parameters.AddWithValue("description", request.descritpion); com.Parameters.AddWithValue("deadLine", request.deadLine); com.Parameters.AddWithValue("idProject", request.idProject); com.Parameters.AddWithValue("taskTypeName", request.taskType.name); com.Parameters.AddWithValue("idAssignedTo", request.idAssignedTo); com.Parameters.AddWithValue("idCreator", request.idCreator); com.Transaction = transaction; com.ExecuteNonQuery(); } transaction.Commit(); connection.Close(); }